Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Could not load file or assembly 'XXX.YYY' or one of its dependencies. The system cannot find the file specified."

I have a .net visual studio solution with a number of projects (class libraries and a web application).

I did some refractoring which moved files between projects, created new projects, deleted ones not being used and renamed some existing projects.

The solution builds without an issue but when I run the web application, the following exception occurs:

"Could not load file or assembly 'XXX.YYY' or one of its dependencies. The system cannot find the file specified."

The project called XXX.YYY which was deleted in the refractoring outputed a dll called XXX.YYY. But this isnt used anywhere in the application. I deleted the web applications obj directory and bin folder and rebuild but it still occurs.

Anyone have any ideas when this might be occurring, any tips??

UPDATE:

Update on my issue. I took the code place to another computer and ran it from there and it built and ran successfully without this issue occurring. So this makes me think the issue is with my PC rather than the code base. Maybe there is something cached on my PC. I did delete my temp files at "C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files" but no luck.

So anything else that could be cached or any other reason for it to occur on my PC.

FURTHER UPDATE

Another update on this. I have ran the same code on other developers machine and he doesnt have an issue running it. So must definitely be something on my machine! The only different on our machine is that I am running IIS7 with the app's app pool in classic mode. The other developer is running IIS6.

2 new pieces on information. Firstly in my httpmodules in my web.config, I have to remove a custom http module, before adding it. The other developer does not have to do this. Secondly, I have been able to fix the "Could not load file or assembly 'XXX.YYY' or one of its dependencies" issue via a "hack" which is only a short term fix by creating a class library in my project called XXX.YYY and including the classes being looked for, which are all custom controls ie. inheriting from System.Web.UI.WebControls.WebControl.

Any further thoughts....

like image 610
amateur Avatar asked Jan 01 '11 23:01

amateur


5 Answers

There are two possible reasons.

1) When you run your webapp, you still use the old assemblies somewhere on your machines. Your old assemblies were referencing the old assembly "XXX.YYY".

2) The latest binary you built is still referencing the old assembly "XXX.YYY".

To find out what assemblies your webapp using, if you are running a debugger, you can easily find it out from the output windows. It should be first few lines of the output. Another way to find out is to open the Module windows in VS.NET IDE during debugging.

If you cannot debug it for some reasons or you have problems to attach a debugger, another easier way to do is to use fuslogvw. It gives you the exact locations of all successfully loaded assemblis as well as the assemblies that it failed to load. Please make sure you run the fuslogvw as Administrator in Windows 7.

After you find out what assemblies your webapp successfully loaded, you can do ildasm on those assemblies to see what assemblies they are referencing. You need to check them one by one unfortunately.

My guess is that some of your successfully loaded assemblies are actually coming from somewhere in the ASP.NET cache or GAC.

like image 194
Harvey Kwok Avatar answered Oct 16 '22 01:10

Harvey Kwok


Enable Diagnostic logging for the build output (TOols -> Options -> Build And Run -> Output Log verbosity -> Diagnostic) and Build the solution and see from where Visual Studio picks the dll (somedll.dll version xxx.yy). Now run the Application and see where the runtime is trying to resolve the dll. (Windbg is an option).

like image 21
Soundararajan Avatar answered Oct 15 '22 23:10

Soundararajan


just check the projects build configuration.. if there is an 64 bit compiled dll on your references and your main project is 32 bit (or any cpu and your machine is 32 bit) or vice versa you wil get this error

like image 24
Tolgahan Albayrak Avatar answered Oct 16 '22 00:10

Tolgahan Albayrak


Do solution search for the text "XXX.YYY" and delete all occurences. Maybe you have sth left out in some web.config file.

Additionally you can check the *.csproj files if solution search finds nothing. They're basically text files, so there should be no problem removing references.

like image 23
dzendras Avatar answered Oct 15 '22 23:10

dzendras


Use the Dependency Walker (depends) on all of your EXEs and DLLs to see which one has the dependency that is missing. You should run depends from the working directory of your project for best results.

Once you know which EXE/DLL is the culprit, go into the settings for that project and see if the complained about dependency is mentioned there.

EDIT: Another thing occurred to me a few minutes ago... If any of your dependencies are "blocked" because they were marked as downloaded by some MS tardware (When you DL with Inet explorer for example) that can prevent executable code from loading. Look at the properties of your executables (DLL/EXE) with Windows Explorer and see if they have an unblock button on the first page. If so, click that button. This took me some time to figure out a while back, hopefully it'll help.

like image 1
JimR Avatar answered Oct 16 '22 00:10

JimR