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

Posted on 2009-06-28
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:

(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=, 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.
Question by:saragani
  • 6
  • 4
LVL 11

Expert Comment

ID: 24735598
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.
LVL 11

Author Comment

ID: 24735739
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.

LVL 11

Author Comment

ID: 24735789
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.
LVL 11

Expert Comment

ID: 24735815
When you are adding references to these assemblies, how are you adding them?
LVL 11

Author Comment

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

How else would I do it... Manually? (I'm not that insane).
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

LVL 11

Author Comment

ID: 24736399
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=, 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"
LVL 11

Accepted Solution

William earned 500 total points
ID: 24736527
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.
LVL 11

Author Comment

ID: 24736651
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?
LVL 11

Author Comment

ID: 24736687
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 :-)
LVL 11

Expert Comment

ID: 24736794
Do you have a namespace architecture you are using....
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

Expert Comment

ID: 31717420
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.

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now