views:

60062

answers:

13

I am trying to run some unit tests in a C# winforms application (VS 2005) and I get the following error:

System.IO.FileLoadException: Could not load file or assembly 'Utility, Version=1.2.0.200, Culture=neutral, PublicKeyToken=764d581291d764f7' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

at x.Foo.FooGO() at x.Foo.Foo2(String groupName_) in Foo.cs:line 123 at x.Foo.UnitTests.FooTests.TestFoo() in FooTests.cs:line 98

System.IO.FileLoadException: Could not load file or assembly 'Utility, Version=1.2.0.203, Culture=neutral, PublicKeyToken=764d581291d764f7' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

I look in my references and I only have a reference to Utility version 1.2.0.203 (the other one is old)

Any suggestions on how I figure out what is trying to reference this old version of this dll?

Also, I don't think I even have this old assembly on my hard drive. is there any tool to search for this old versioned assembly.

+26  A: 

The .NET Assembly loader is unable to find 1.2.0.203, but did find a 1.2.0.200. This assembly does not match what was requested and therefore you get this error. In simple words, it can't find the assembly that was referenced. Make sure it can find the right assembly but putting it in the GAC or in the application path. Also see http://blogs.msdn.com/junfeng/archive/2004/03/25/95826.aspx.

Lars Truijens
but when i look at references of the project, it is pointing to 1.2.0.203 .. . nothing seems to be pointing to 1.2.0.200 anymore
ooo
Exactly - it's *looking* for 1.2.0.203, but it *found* 1.2.0.200. Find out where that file is and replace it with the right version.
Jon Skeet
+11  A: 

You can do a couple of things to troubleshoot this issue. First, use Windows file search to search your hard drive for your assembly (.dll). Once you have a list of results, do View->Choose Details... and then check "File Version". This will display the version number in the list of results, so you can see where the old version might be coming from.

Also, like Lars said, check your GAC to see what version is listed there. This Microsoft article states that assemblies found in the GAC are not copied locally during a build, so you might need to remove the old version before doing a rebuild all. (See my answer to this question for notes on creating a batch file to do this for you)

If you still can't figure out where the old version is coming from, you can use the fuslogvw.exe application that ships with Visual Studio to get more information about the binding failures. Microsoft has information about this tool here. Note that you'll have to enable logging by setting the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion\EnableLog registry key to 1.

Seth Petry-Johnson
+4  A: 

I just ran across this issue and the problem was I had an old copy of the .dll in my application debug directory. You might want to also check there (instead of the GAC) to see if you see it.

Neal Tibrewala
+4  A: 

I just ran into this problem myself, and I found that the issue was something different than what the others have run into.

I had two DLLs that my main project was referencing: CompanyClasses.dll and CompanyControls.dll. I was getting a run-time error saying:

Could not load file or assembly 'CompanyClasses, Version=1.4.1.0, Culture=neutral, PublicKeyToken=045746ba8544160c' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference

Trouble was, I didn't have any CompanyClasses.dll files on my system with a version number of 1.4.1. None in the GAC, none in the app folders...none anywhere. I searched my entire hard drive. All the CompanyClasses.dll files I had were 1.4.2.

The real problem, I found, was that CompanyControls.dll referenced version 1.4.1 of CompanyClasses.dll. I just recompiled CompanyControls.dll (after having it reference CompanyClasses.dll 1.4.2) and this error went away for me.

Nathan Bedford
+3  A: 

For us, the problem was caused by something else. The license file for the DevExpress components included two lines, one for an old version of the components that was not installed on this particular computer. Removing the older version from the license file solved the issue.

The annoying part is that the error message gave no indication to what reference was causing the problems.

Sire
A: 

Try adding whatever's missing to the global assembly cache.

nikonica
+1  A: 

If you are using Visual Studio, try "clean solution" and then rebuild your project.

Tad
+1  A: 

This exact same error is thrown if you try to late bind using reflection, if the assembly you are binding to gets strong-named or has its public-key token changed. The error is the same even though there is not actually any assembly found with the specified public key token.

You need to add the correct public key token (you can get it using sn -T on the dll) to resolve the error. Hope this helps.

Guy Starbuck
Please elaborate - what is "sn -T"? And where do I add the public key token?
Moritz Both
"sn.exe" is a tool that comes with Visual Studio, it's a command line tool that can be run from the Visual Studio command prompt. Just run the Visual Studio command prompt (from the start menu), navigate to the folder that contains your assembly, and type "sn -T <assembly>" where <assembly> is the full name of the dll. This gets the Assembly "Token" information. Once you have this, when you are doing late binding with reflection, enter the token info into the assembly id string (i.e., "Assembly=MyAssembly.dll, Public Key Token=<token guid>)
Guy Starbuck
Thanks for this answer. I was getting this error when referencing a Configuration Section in my App.ini. I had recently signed the assembly, so the PublicKeyToken=null had to be updated with the new (correct) token.
Liam
+1  A: 

issue resolved with an iisreset

ttt
Worked for me too!
NLV
A: 

Mine was a very similar situation to the post by Nathan Bedford but with a slight twist. My project too referenced the chagged dll in two ways. 1) Directly and 2) Indirectly by referencing a component (class library) that itself had a reference to the changed dll. Now my Visual studio project for the component(2) referenced the correct version of the changed dll. However the version number of the compnent itself was NOT changed. And as a result the install of the new version of the project failed to replace that component on the client machine.

End result: Direct reference (1) and Indirect reference(2) were pointing to different versions of the changed dll at the client machine. On my dev machine it worked fine.

Resolution: Remove application; Delete all the DLLS from application folder; Re-install.Simple as that in my case.

BishopOfNairobi
A: 

Right click the reference in VS set "Specific Version" property to True.

Adam
A: 

In my case it was an old version of the DLL in C:\WINDOWS\Microsoft.NET\Framework\~\Temporary ASP.NET Files\ directory. You can either delete or replace the old version, or you can remove and add back the reference to the DLL in your project. Basically, either way will create a new pointer to the temporary ASP.NET Files.

Glade Mellor
A: 

Tried Glades Mellor deleting the temp asp.net folder and all fixed. Nice

jin14