Could not load file or assembly (DarkRift) - c#

I've been struggling with a problem in Unity and I would appreciate it if anyone can help me.
I'm using a package called DarkRift, which is used for networking and connecting clients with a server (provided by DarkRift). In order to work with the DarkRift server, I need to write plugins. A plugin is basically a visual studio project, compiled to .dll file, then that file is copied to a certain directory on the server-side.
I've been working with DarkRift for some time now and have done so much with it. It was working perfectly! However, I needed to work with Firestore package from Google.
Hence, I created another plugin, installed Firestore (and every package needed), wrote some simple code using one of Firestore's functions, compiled the project, copied .dll to the server, then ran the server. The problem is whenever I run the server (.exe file), I get an error that says: "Could not load file or assembly 'Google.Cloud.Firestore, Version=1.0.0.0, ...' or one of its dependencies."
I get this error when I use any of Firestore's functions. However, if I just include the package (using Google.Cloud.Firestore;) without using any of its functions, I don't get any error. I googled this problem and looked everywhere and could not solve it.
Thanks!

Firestore is distributed as a Nuget package, which indeed has dependencies.
Have you also copied all those dependencies to the server?
It might also be a framework incompatibility.
To get more details about this kind of problem, you can register a logging event handler on AppDomain.AssemblyResolve, which fires when assembly resolution fails.
You can also use tools like dnSpy to dig into the problematic assembly - it shows you all sorts of metadata and it can decompile the CIL, which is invaluable for debugging strange behavior in third party code.
Assembly loading is kind of slow in .Net, so it only loads them when needed.
Hence the resolution does not fail when no code references the assembly.

Related

Unity 3D failed to load plugin 'opencv_world460.dll' because one or more of its dependencies could not be loaded

I'm trying to load and use the opencv library in Unity via a custom plugin dll and opencv_world460.dll (which I also compiled myself from source). The plugin works fine and I am able to pass data to and from Unity managed memory and the unmanaged C++ .dll plugin. The plugin itself is also able to reference, call, and link against my opencv headers and compiled libraries. However, when attempting to load opencv_world460.dll Unity throws an error stating:
"Plugins: Failed to load 'Assets/Plugins/opencv_world460.dll' because one or more of its dependencies could not be loaded."
To find the source of my problem I ran the dependency tracing tool "Dependency" on opencv_world460.dll. As far as I can tell, the tool is able to resolve all of the dependencies required the run this dll on my machine. Obviously Unity is still unable to find or load one of them for whatever reason. The attached image is the dependency list for opencv_world460.dll. The dependency tool I was using doesn't appear to supply any easy way of copying the text, so I had to use the image.
Does anyone have any suggestions about how to track down specifically which dependency is failing to load? My best guess is there's a problem with all of the api-ms-win-crt dll's being forwarded to ucrtbase.dll. In the meantime, to test this theory, I'm going to go download the redistributable containing those actual dlls and install it to see if that has any impact on the problem.

How to debug an FileLoadException in an Azure Function

I have an Azure Function (.netstandard 2.0) that fails to run because of FileLoadException. Normally I would use Fuslog to find out which dependency is missing but I have not found a way to RDP the machine running my Azure Function. Right now, through various logs, I only get the following information:
System.IO.FileLoadException : Could not load file or assembly
'Microsoft.WindowsAzure.Storage, Version=9.1.1.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35'. Could not find or load a specific
file.
I can see that the right version of the file is actually there via Server Explorer. So it seems to be a dependency issue.
How can I debug this?
Basically your Function App is a plug-in which gets loaded into runtime. Runtime has its own dependencies, and if you happen to use the same dependency but of higher version, you get a runtime error.
WindowsAzure.Storage is definitely in this list.
For runtime v1 the most reliable way to figure out the exact versions is to look into this file, just search for the package in question.
Runtime v2 doesn't have it yet.
Then downgrade your reference to the same version.
A better solution is discussed in this issue.

MySql.Data reference in my own .dll only functions on development computer, not on end user's computers

I have a question as a novice programmer regarding a MySql.data reference I added from the MySql connector net, to my code. The program that I compile would be made into a .dll that runs from within another application. The application is a stock trading program, and my code is a strategy that makes evaluations of price data and executes buy and sell orders, etc.
Just when I thought my strategy was fully developed I've run into a new snag I'd love to have someone's help with in solving.
I'm asking stackoverflow because the support forum mods of the trading application removed this question from their forums, probably because it was outsie their supportable boundaries.
I've been adding extra .NET references to my strategy, like windows forms and system.management, etc so that it would be able to check the computer's hard drive 'serial number' to make sure that the strategy is licensed on that computer. Everything has been working ok so far, and I was able to get the strategy to run on other computers by exporting it as a .dll
The latest and final addition I made was to add a reference to MySql.Data.MySqlClient (which is a .dll that had to be downloaded and installed separately and isn't part of .NET) so that it could check the computer's hardware ID against an online database to see if it's on the whitelist. I got that working perfectly on the development computer, and as soon as I tried to get it running on my other computer, this error message came up in the output window:
NT Error on calling 'OnStartUp' method for strategy 'MyStrategy/7f5e28c481644cb5a7754d0b7a0be47f': Could not load file or assembly 'MySql.Data, Version=6.1.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies. The system cannot find the file specified.
I don't fully know what is happening, but it seems that in the past all external .dll from microsoft .NET that I referenced in my code were carried over and functioned perfectly on other computers, and while my code runs with the MySql.Data reference, once any MySql commands are run the program terminates and says that error message about a missing file. (But if I comment out those lines of code it runs fine, just without the licensing checks I need to have)
One last thing I can mention for more information, as I'm new to this area of development and don't know if it matters, is that I installed the most recent MySQL connection net to the laptop which is a later version than the 6.1.6.0 that I have on the development computer.
The strategy runs exactly as intended on the computer it was developed on though.
My main question has two parts to it then:
1) Is there a way to embed or merge the MySql.Data .dll so that it can be a part of my .dll?
2) Will every end user of this software need to have MySql connection net installed on their computer, and the exact same version as whatever it was developed in (noob question)
Any answers, guesses and speculation are welcomed and appreciated.
Just check if your programs output directory contains the MySql.Data dll file.
If not Try to copy the MySql.Data dll file to the output directory of your program.
it should solve your problem.
The problem happens because may be you are referencing the MySql.Data dll from any other directory rather then copying it to the local project directory. or may be it is not copying into your projects output directory.
So when you run the program to another machine it is unable to find the MySql.Data dll file in specified directory and says
MyStrategy/7f5e28c481644cb5a7754d0b7a0be47f': Could not load file or
assembly 'MySql.Data, Version=6.1.6.0, Culture=neutral,
PublicKeyToken=c5687fc88969c44d' or one of its dependencies. The
system cannot find the file specified

Plugin with references not working on CRM 2011

I have created a plugin and used a reference to another project (DLL) I have created. The problem is when I try to run the plugin, I get a CRM error saying:
Could not load file or assembly 'XXX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a760feb9ec7271a9' or one of its dependencies. The system cannot find the file specified.
Does anyone have any idea on solving this one?
You have to deploy the referenced assembly either to the GAC or merge it with your one (with ILMerge)
See also http://msdn.microsoft.com/en-us/library/gg309620.aspx and Creating a single CRM plugin DLL to store in the CRM database
I have a blog post here on how you can put it all in 1 DLL without ILMerge:
All References within CRM2011 plugin. We've yet to have a dll issue since we started doing this.
NB this approach rules out the use of Sandboxed mode (i.e., you will not be able to use this approach should you require your plugin to work in Dynamics CRM Online).
We have had this error several times over the last 6 months and each time, despite me or the other developers swearing blind it would not be the case, it has turned out to be a DLL version problem.
Are you installing the plugin to disk, DB or GAC?
If installing to the GAC, I believe external DLLs go in the GAC as well.
If installing to the DB or to disk, I believe DLLs go in the \assembly\bin folder.
Sometimes the Anti-Virus will prevent ASP.NET from accessing file or assembly, I suggest you try to sign the assembly with strong name and add it to GAC: Here you can find more information http://support.microsoft.com/kb/815808

Assembly references won't resolve properly on our build server

We code in C# using VS2008 SP1. We have a server that runs Team System Server 2008 which we use for source control, tasks etc. The server is also our build machine for Team Build. This has been working just fine for a long time. Untill now. We get these error messages when trying to build one of our projects that has a reference to one external assembly (this happens both via Team Build, and when logging on physically and doing a regular build via Visual Studio):
C:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.Common.targets
: warning MSB3246: Resolved file has a
bad image, no metadata, or is
otherwise inaccessible. Could not load
file or assembly 'C:\Program
Files\Syncfusion\Essential
Studio\7.1.0.21\Assemblies\3.5\Syncfusion.XlsIO.Base.dll'
or one of its dependencies. The module
was expected to contain an assembly
manifest.
C:\Program
Files\MSBuild\Microsoft\VisualStudio\v9.0\ReportingServices\Microsoft.ReportingServices.targets(24,2):
error MSB4062: The
"Microsoft.Reporting.RdlCompile" task
could not be loaded from the assembly
Microsoft.ReportViewer.Common,
Version=9.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a. Could
not load file or assembly
'Microsoft.ReportViewer.Common,
Version=9.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a' or
one of its dependencies. The module
was expected to contain an assembly
manifest. Confirm that the
declaration is correct, and that the
assembly and all its dependencies are
available.
The referenced component
'Syncfusion.XlsIO.Base' could not be
found.
These errors are for one project with one problematic assembly reference. When I try to build the entire solution there are of course many more errors because of this one. And there are two other projects that has the same problem with other assembly references. I have a list of the referenced assemblies that VS can't seem to resolve:
Microsoft.ReportViewer.Common
Microsoft.ReportViewer.WinForms
Syncfusion.Compression.Base
Syncfusion.Core
Syncfusion.XlsIO.Base
The Syncfusion assemblies are from a 3rd-party component package. The other two are related to the Microsoft ReportViewer component.
The references has been added via the Add Reference window, in the .NET tab, so I don't think there is anything suspicious about that. In the properties window for the assembly reference, there is no value in Culture, Description, Path, Runtime Version or Strong Name. Version says 0.0.0.0 and Resolved is False. I guess it is pretty obvious that VS cant resolve the reference. My question is why??? I've scratched my head a lot over this one. This only occurs on the server, the solution builds just fine on both my machine, and my coworkers machine. The assembly reference properties are fine on our machines.
I have tried uninstalling the 3rd-party component (on the server of course), and then reinstalling it again. Didn't help. I tried to repair the VS2008 installation. Didn't help. Tried to retrieve an earlier version from source control (that I know has buildt on the server before), and I got the same error messages. I have checked file permissions, and everything appears to be in order. I am running out of ideas...
How do I solve this?
Update 16.02.2009:
I have tried to compare ildasm output of the dll on my pc and on the server (see the comment I wrote about that), and there is one small difference in a line that to me appears to be a comment. I must admit that I don't understand why there is a difference at all, so maybe someone could explain that to me?
I also tried running a virus scan on the server. Didn't help. Tried to remove the reference and then readd it by browsing to the dll on disk. Didn't work.
Update 17.03.2009:
I've found the solution! The culprit was the TruPrevent module of Panda Antivirus. After disabling the module, everything works! =)
I discovered this with the help of fuslogvw.exe and the log it generated. Googled the result, and stumbled upon this blog entry.. Hope this can help somebody else to.
Almost certainly the problem is environmental - not source related.
Some ideas ...
(i) Try disabling your anti-virus/anti-malware tools - I've seen cases where these tools (particularly Trend Micro Antivirus, for some reason) can keep a DLL file locked after (during?) scanning, interfering with compilers.
(ii) Check your PATH environment variable. Even in these modern days, the PATH variable is used to resolve some things - if this is messed up (too long, maximum length is 2048 characters IIRC) then things can be odd.
(iii) You've checked File permissions - have you checked permissions in the registry? For example, SyncFusion installs its license key in both the User and Machine hives - if the build server can't read one or the other, could cause issues.
Good luck!
It could also be that the referenced assemblies are in the GAC on the dev machine, but not on the build machine. Get it out of the GAC, into your source repository, and reference it by path.
We've had the same problem, turns out the C drive was full (only had 28MB).
Freeing space resolved the issue, even though the build happens on D.
Do you see any differences between ildasm of this file
'C:\Program Files\Syncfusion\Essential Studio\7.1.0.21\Assemblies\3.5\Syncfusion.XlsIO.Base.dll'
on your machine versus on the server?
My suspicion is that the user that the build process is under does not have access to the folder that your 3rd party control is in. Since this functions properly on your machines, it is almost certainly user/permission specific.
Your 3rd party dll may depend on unmanaged dlls. Often it's because a specific version of the VC++ Runtime Dlls are missing.
Open the Dll with the Dependency Walker http://www.dependencywalker.com/ on your server and check for missing references.
Not sure if this'll help in your case, but I did have something similar before where a dll apparently got unregistered somehow, and running regsvr32 on the dll did the trick.

Categories

Resources