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

8

9

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....

Koosis answered 1/1, 2011 at 23:5 Comment(11)
Did you try cleaning up your ASP.NET temporary file directory? C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET FilesCaiman
@Harvey - tried deleting the temp files but still no luckKoosis
@jgritty yes I used reflector on all the dll's in the bin directory of my web application and could not find any reference to XXX.YYY.Koosis
Have you tried using findstr in your project directory just to see who has a reference to xxx.yyy? cd <project base dir>; findstr /I /S /L XXX.YYY - You will get some garbage on the console because at least one binary file will have a reference in it to that name. If there's too much garbage, make 2 passes, one as stated and on the other pass add /M . Note that the /L means the search is literal.Mize
Give CCleaner a try on the bad machine. It cleans up temp directories, internet history etc. You will have to relogin to websites once you run it though. www.piriform.com/ccleanerMize
@Mize - thanks for the suggestion but no luck with this.Koosis
OK... I'm now extremely curious why this is happening. :) 1) Do you have an active anti virus running on the broken machine? Not Symantec or McAfee I would hope. :) If not, use one of the reputable online scanners and then check your problem code again if anything is found/repaired. 2) Is it possible to uninstall Visual Studio, the .Net runtime that is affected by this problem and then reinstall? We had a similar problem way back when the first .Net runtimes were released and found 2 ways to fix things. 1 is the method I described, 2 is a complete reinstall of windows, VS etc...Mize
I had a drama in the past where I was referencing a VB6 ActiveX DLL for which I had the project source for. When moving the project to another PC or moving 'things' around, I'd have to rebuild the DLL in the VB6IDE and reattach the DLL to the references in VS. Not sure if this relates too much, just my two cents since I was getting the same error for some strange reason.Kort
Please see further update to question. The anti virus is same on both machines. I can look at uninstalling the runtime but hope it doesnt come to that! Wonder if its something Windows 7 related.Koosis
Sorry Niall, this is the last of my ideas... It has to do with the way Win7 handles permissions. I'm not a .Net gearhead. This came from an acquaintance that has been dealing with a somewhat similar problem. Look in all the places on the broken machine where assemblies are stored and make sure they have consistent permissions. Use cacls <filename>. He tells me that things in the C:\WINDOWS\Microsoft.NET\Framework that are config files should have at least change permission and DLLs at least read permissions for the NT SYSTEM account and the user for the web server. Worth a look anyway.Mize
@Niall Did you try my suggestion? It shouldn't be hard to figure out any assembly reference issue. The idea is to use fuslogvw to locate what assemblies are using. Then, use ildasm on each of the loaded assemblies. It will tell you what assemblies they are referencing in the manifest section. I think it's worth to try if you haven'tCaiman
K
0

Great news I have solved the issue!!! I had to reinstall my .net runtime environment. I also deleted sites from IIS and readded the website again. When I ran it, the issue did not occur and site ran.

A big thank you to everyone for their help and assistance, very much appreciated. All the advice and help steered me in the direction to solve this!

Koosis answered 8/1, 2011 at 15:22 Comment(0)
C
6

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.

Caiman answered 2/1, 2011 at 18:28 Comment(1)
I also wanted to mention fusion logger, but I couldn't remember the tool name.Monadnock
A
2

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).

Aegisthus answered 7/12, 2011 at 18:28 Comment(0)
B
1

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

Bradybradycardia answered 1/1, 2011 at 23:17 Comment(2)
wouldn't that throw a BadImageFormat exception instead?Banneret
@Banneret - yes.. it does with this description "Could not load file or assembly 'XXX.YYY, Version=1.0.XXX, Culture=neutral, PublicKeyToken=null' or one of its dependencies."Bradybradycardia
M
1

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.

Mize answered 1/1, 2011 at 23:18 Comment(4)
Using windows explorer, I right clicked on all dll's in the bin directory and viewed properties. I did not see block/unblock anywhere. Where should I see it if its pertinent to this? I have not used Dependency Walker before so I am novice as to how this work. Do I open each dll in my bin directory with it? (Note: the bin directory is that of the web application, do I need to do it for all class libraries? I have 30+!)Koosis
Dependency Walker resolves the DLL dependency from import and export table of PE as far as I know. Unless he is using some unmanaged DLL, I don't see how dependency walker going to help. Is the latest dependency walker can walk through the reference of assembly too?Caiman
@Niall Collins: There is no block option, only unblock. If you don't see it you should be OK.Mize
@Harvey Kwok: I've used Dependency Walker in a similar situation and resolved problems. I'm not sure how it works, but it has worked for me.Mize
H
1

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.

Heterogeneous answered 1/1, 2011 at 23:48 Comment(1)
tried searching the entire solution (all files) for XXX.YYY but no luck finding any references. thanks for your inputKoosis
D
0

You are simply missing a dependency. Its probably a situation like Project A has a reference to Project B which has a reference to Project C. Your output directory is missing the DLL for Project C.

Daffi answered 2/1, 2011 at 0:15 Comment(3)
But if this is the case the solution wouldn't build - correct? Solution is building ok.Koosis
@Niall Not necessarily. All the projects are in the same solution, so each project has its required references and all are built in the order necessary to build up the dependencies. For a published app, as long as the bin folder contains all the DLLs required then the app will run, but if a single DLL is missing then you'll see the problem you're experiencing. Are you publishing the app to IIS or just debugging in VS?Daffi
Interesting. I am running it on my local IIS7 on windows 7 pc. Should this matter?Koosis
K
0

Great news I have solved the issue!!! I had to reinstall my .net runtime environment. I also deleted sites from IIS and readded the website again. When I ran it, the issue did not occur and site ran.

A big thank you to everyone for their help and assistance, very much appreciated. All the advice and help steered me in the direction to solve this!

Koosis answered 8/1, 2011 at 15:22 Comment(0)
P
0

Go to References in Solution Explorer in Visual Studio. Select the assembly which is getting complained. Select it and go to View menu option and select Property Window at the bottom. While the assembly is selected, view its properties in the property windows and look for Copy Local value. If its value is set to False, set it to True. Build the solution and publish it. It should successfully solve the problem.

Psychosomatics answered 25/8, 2015 at 8:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.