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

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.
LVL 11
saraganiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

WilliamCommented:
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
0
saraganiAuthor 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.

0
saraganiAuthor 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.
0
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

WilliamCommented:
When you are adding references to these assemblies, how are you adding them?
0
saraganiAuthor Commented:
Using visual studio --> Add reference --> Browse -->  Selecting the DLL.

How else would I do it... Manually? (I'm not that insane).
0
saraganiAuthor 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"
0
WilliamCommented:
Yes - I did not mean you were insane :) - I have this problem in the past, and when I would ref the dll directly...  it does not always like it. So I reference the projects instaed.
THis solves the issue and allows me to debig as well.
 
YES -I saw the error after I opened the form .. closed.. and reopened.
Try referenceing the proj files instead of the dll's.
Unless the dll is actually a production release use the proj. If it is in production release...  and it is a USER CONTROL or a COMPONENT --  Add theses types to the toolbar and drag them to your form.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
saraganiAuthor 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?
0
saraganiAuthor 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 :-)
0
WilliamCommented:
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
0
anugrahCommented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.