We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

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

saragani
saragani asked
on
Medium Priority
14,212 Views
Last Modified: 2012-05-07
This looks like a bug by microsoft, it is pretty annoying and I'm wondering if anyone has a solution, or maybe I'm doing something wrong (And in this case, what am I doing wrong and how to do it right)

I have noticed that on several user controls that I've created... some projects that had the user control on a form were giving this error when opening the solution... it will happen if the form that contained the user control was opened.

Closing the form and reopening it would "fix" the problem (The error will be gone).

At first I thought I did something wrong and started investigating... after I didn't find anything I did some tests and in one of them I found out that removing one of the projects from the solution and then adding it back solved the problem... Off course this has no sense so I started checking why got changed... It seems that the only difference is in the Solution file.



I've made a simple example:
http://rapidshare.com/files/249837223/BigMike.rar.html



(Sorry for  the stupid/weird names... I've ran out of reasonable names)

Open BigMike solution. You should see that you get an error
Open BigMike2 solution. You should see that it opens OK without any error.

The only difference between those 2 is the order of the projects in the solution, which ultimately cases the error:

Could not load file or assembly 'RedEye, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

Instances of this error (1)  
 
1.   Hide Call Stack
 
at BigMike.Mike..ctor()  


It claims that it fails on the constructor.


I see no reason why the projects order would prevent loading an assembly.

I'm using Visual Studio 2008 if that matters.

Thank you.
Comment
Watch Question

Commented:
I have opend both without errors...
Can you try something for me...
In the IDE open the solution that gives you error.
In solution explorer, right click the top node 'solution itself' and click clean.
rebuild solution and try again to open.
Thanks

Author

Commented:
Same thing (problem is not solved)

When you opened the projects Form1 was opened?

If not then:
1) Open the "BigMike" solution by double clicking the sln file.
2) Double click on Form1 to show it's design.
3) Close visual studio
4) Double Click on the sln file again.

Author

Commented:
I've just tested it on a coworker's computer and he gets the same problem.
He has a totally different computer, with Vista (and not XP like me), and he has different softwares installed on his computer.


It means that you should be able to recreate the problem in your computer using the steps I wrote above.

Commented:
When you are adding references to these assemblies, how are you adding them?

Author

Commented:
Using visual studio --> Add reference --> Browse -->  Selecting the DLL.

How else would I do it... Manually? (I'm not that insane).

Author

Commented:
Did you manage to see the problem that I saw talking about using the instructions I gave?

If so then you can code your own projects and see the problem:

1) Create a user control project.
2) Add a new Class Library project to that solution or add a reference to an existing DLL.
3) Make the user control does something with the DLL (so it will be compiled by the JIT, if it's not needed then it doesn't help). Have that code be after the call for the InitializeComponents (I don't know if that matters). (For example create a new instance of a class of that DLL)
4) Compile the user control

5) close that solution

6) Create a new solution with a Class Library project.
7) Add a new WinForms project to that solution
8) Add the user control that you have created to the toolbox
9) Add the user control to Form1
10) Since I assume that a reference to the DLL that you have created earlier (the one that the user control reference to) was not added to the references of the Winforms project, then add it to the Winforms project
11) In the constructor of the form, create a new instance of a class of that DLL.
12) Compile
13) Double click on Form1 so the design will be visible
14) Close the solution
15) Open the solution


You get the error:

"Could not load file or assembly 'ClassLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.    
 

Instances of this error (1)  
 
1.   Show Call Stack  
 
at bbb.UserControl1..ctor()  
   
Help with this error  
 
Could not find an associated help topic for this error. Check Windows Forms Design-Time error list  
   
Forum posts about this error  
 
Search the MSDN Forums for posts related to this error  

 
The variable 'userControl11' is either undeclared or was never assigned.     Go to code  
     
Instances of this error (1)  
 
1.   ppp Form1.Designer.cs Line:47 Column:1   Show Call Stack  
 
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.Error(IDesignerSerializationManager manager, String exceptionText, String helpLink)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager manager, String name, CodeExpression expression)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager manager, String name, CodeExpression expression)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager manager, CodeStatement statement)  
   
Help with this error  
 
MSDN Help  
   
Forum posts about this error  
 
Search the MSDN Forums for posts related to this error"
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Author

Commented:
Yes, I don't that referring the project helps (I did this in the past), but the user control and the DLLs that I create are meant to be deploys for the usage of other people.

They will not use the project itself but the assemblies.

As I already mentioned, adding to the toolbar doesn't help (This is how I've added it to the form in the first place).
The problem is that the User Control constructor fails because of the DLL it refers. :-(
The funny thing is that if you got that error and then you close the form and reopen it then everything is OK.
 
Adding my assemblies to the GAC might solve the problem, but this is something I prefer not to do.


Is there anything else I can try to solve this problem?

Author

Commented:
Anyway, leave your comment here for any suggestions you might have of solving this error (Or maybe how to contact microsoft and report about this issue).

I'm giving you these points because you tried to help.

Feel free to suggest some other solutions if you think of them.


Thank you :-)

Commented:
Do you have a namespace architecture you are using....
Mikes
Mikes.RedEeye
Mikes.BigGuy
ect....
The issue I see is not a MS issue, but one I have had in the past that is:
The DLL the proj is referencing, references another dll outside the namespace... and is not 'pulled' in untill a build is performed. If you can roll these into a single dll or create a namespace hiearchy with a 'release' folder that all the dll'soutput too. this may solve the issue.
In your solution you can change the output dir to anything you like, I have my own 'wannabe' framework that I dump to the same dir after every build. THis ensures every proj I use them in pulls in the latest.
I also add a pre build line to the proj.
erase *.dll
this removes all dll's proir to the build and pulls in the latest.
Hope this helps and thanks for the points

Commented:
I am using a WCF service, I have hosted the WCF service as a Managed windows service, so that on start of the Windows service the WCF service will be invoked and I am calling this wcf service through a a windows app(a winforms) as the service is responsible for the database connection.But is showing the same error,
Could not load file or assembly 'MSDOTNET.MSDB" (which is a our conpany own framework assembly.)
or one of its dependencies.The system cannot find the file specified,
Any help would be highly appreciated.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.