Could not load file or assembly Not exact version - c#

I'm using MigratorDotNet to do migrations. I give it a string to my Assembly My_Assembly which is built on Sharp Arch v2. Sharp Arch v2 is built on Fluent Nhibernate 1.3.0.727.
My project is using 1.3.0.737
I'm getting the following error when MigratorDotNet calls Assembly.GetExportedTypes:
System.IO.FileNotFoundException: Could not load file or assembly 'FluentNHibernate, Version=1.3.0.727, Culture=neutral, PublicKeyToken=8aa435e3cb308880' or one of its dependencies. The system cannot find the file specified.
I'm familiar with BindingRedirects but would prefer to not change source code for MigratorDotNet (it does't pull in external config).
Is there a way I can force the new version and prevent the FileNotfoundException?
P.S. I know there a lot of similar-phrased questions but those are usually resolved by binding redirects, ensuring Copy Local = true, adding assemblies to the GAC, etc. I think this question is more generic.

I hate to say it, but I think you are going to have to live with binding redirects. I've not found a way to do what you are asking yet myself, but would love to see if there is one.

Related

.Net DLL reference error (after strong name sign)

Here is my scenario.
I have Few applications using ABCD.dll (written in C# .net), this old DLL was NOT strong name signed.
I modified this dll basically kept the same name ABCD.dll and signed it with the key. Please note there is no code change
I thought I should be able to just place this newly updated DLL into different applications folders and it should work. Am I wrong?
I am getting following error
BadImageFormatException: Could not load file or assembly 'ABCD, Version=7.2.1.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
How do I use this new dll without compiling all the old applications?
Am I wrong?
Yes, basically. Changing the signature on a DLL, including from "not having one" to "having one" is a breaking change - it changes the identity of the DLL as far as the CLR is concerned.
How do I use this new dll without compiling all the old applications?
You don't, as far as I'm aware. I don't know of any way of getting that to work. I suggest you take the hit and rebuild everything.
You can, if you're lucky 'just' change the reference to the new .DLL. There are tools for this.
You can try this one: https://marketplace.visualstudio.com/items?itemName=markkemper1.ReferenceSwitcher

How do i add dependencies to ASPX forms project? (nuget already tried)

I have worked with asp forms long time ago, now i must create a simple web interface, which uses powershell library.
[Nuget URI][1]https://www.nuget.org/packages/System.Management.Automation/
But seems impossible.
using System.Management.Automation; <-- doesn't work any place.
Already tried installing the usual way (via cli and giu), copying the library to \bin folder and many other ways.
I often get the error:
Severity Code Description Project File Line Suppression State
Error Could not load file or assembly 'System.Management.Automation, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Strong name signature could not be verified. The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045)
I am trying Web Forms because of simplicity, hope i am missing a simple thing.
Any help will be appreciated.
It was a version incompatibility, as mason pointed out on 1st post comments. Use the OS library located on C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Management.Automation\v4.x.x.x.x__xxxxxxxxxxxxxx
.net Framework aspx is getting complex, don't be fooled on other kind of projects or scripts where you can use any binary you can find.
I used "\sn.exe -Vr yourDll.dll", and "sn.exe -Vl" to register and check the nuget library to GAC but, i got another error:
Could not load file or assembly 'System.Runtime.Extensions
Seems i must use the actual OS library, otherwise it won't work.
Also tried creating custom libraries and workes (myClass1 worked), no GAC registry needed.
Also tried downloading mysql official library, which registers, and worked.
Anyways, hope helps to someone.

Could not load file or assembly (DarkRift)

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.

Visual Studio could not load file or assembly; maybe cached?

When I run unit testing to serialize to an xml file, I keep getting error message:
Could not load file or assembly
'Company.Fin.Bank.Common.XmlSerializers.dll, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null' or one of its dependencies. The
system cannot find the file specified.
I guess Company.Fin.Bank.Common.XmlSerializers.dll may be in cache somewhere but it is impossible to find this dll, even though i don't need that dll. I want to remove it. But where can i find it? is it possibly in a cache? if yes how can i clean the cache from VS? This problem is very new to me.
What a weird part is that i used another laptop (win 7) to run the unit testing, there is no error message i got - it worked. but when i used my own laptop (win 8) i keep getting error message. I have no idea why.
I hope to find solution from you. Your help means alot. Thanks!!!
That assembly is dynamically generated by the framework (XMLSerializer)
In .Net implementation, the XmlSerializer generates a temporary
assembly for serializing/deserializing your classes (for performance
reasons).
Also, this may be normal behavior - is it stopping your application from running?
even though i don't need that dll
Visual Studio will usually remove unneeded DLLs. Typically this is caused by dependencies (which are harder to keep track of).
I want to remove it.
Check in the References of the project in the Solution Explorer. If any of them have a yellow triangle that means they can't be found (the project may still compile and run if you aren't actually using that reference).
is it possibly in a cache?
As Daniel Kelley mentioned C:\Windows\assembly and C:\Windows\Microsoft.NET\assembly are where the global assembly cache is located. If it isn't there check the Hint Path of the reference (it will show up in Properties).
Good luck finding your reference, keep in mind that you need not only the actual DLL but all of its used references in most cases. Also a decompiler like DotPeek can be useful if you need a more discreet way of looking at references.

Finding where an old NHibernate DLL is referenced

I'm working on a ASP.NET MVC C# project and I'm getting the following error when launching the web app:
Could not load file or assembly 'NHibernate, Version=2.1.0.1001, Culture=neutral, PublicKeyToken=aa95f207798dfdb4' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Based on the error and some googling it seems clear that there is something referencing a NHibernate dll version 2.1.0.1001. However, our project is using NHibernate version 2.1.2.4000 (old, I know). I've searched the entire solution for any references to that version of NHibernate and cannot find one. I'm assuming that another DLL that we're using is referencing it, but I don't know the best place to start to figure out which.
Am I on target with what the issue likely is? Any (hopefully free) dependency tools that anyone can recommend?
I think you are on-target with the basic issue. Consider a stale output file from your solution too. A rebuild (i.e. clean and build) should cover that possibility.
A good free tool for checking references in assemblies you reference is Telerik JustDecompile.
Also, Fuslogvw.exe (Assembly Binding Log Viewer) may shed some light on the load error.

Categories

Resources