Click here to Skip to main content
15,901,426 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

In my csharp application when i tried to load a dll called mytest.dll by using

Assembly a = Assembly.LoadFrom("mytest.dll");

It show an error like

Could not load file or assembly 'file:///C:\Users\DEVP\Documents\Visual Studio 2008\Projects\ConsoleApplication1\ConsoleApplication1\bin\Release\mytest.dll' or one of its dependencies. The system cannot find the file specified.


i copied mytest.dll to C:\Users\DEVP\Documents\Visual Studio 2008\Projects\ConsoleApplication1\ConsoleApplication1\bin\Release\

also...
Posted
Comments
CPallini 12-Sep-13 4:40am    
"or one of its dependencies" might be the key.
Did you write the DLL on the same machine?

1 solution

The exception (not error!) is self-explaining. You should make sure than the DLL in question is placed to the output directory of the project containing the code loading it. Alternative solution would be providing the "app.config" file which can be used to provide a "hint" path where this DLL can be found during runtime (if you are interested, I'll give you the information on this technique, just ask me a follow-up question, but this is not the main approach, but it has limited applicability).

If "mytest.dll" is build by your project, the best way to deal with that would be putting the this project in one solution with the project containing the code loading it. Then, if assemblies are dependent statically, you normally add references to the projects, not assemblies, by using the tab "Projects" of the "Add Reference" window. It won't help if you load "mytest.dll" dynamically, during runtime. So, it would be the best if you modify all your products to have output directories (separate for each Configuration or Configuration/Platform combination) in the same directory. For example, I usually use the paths like "..\..\..\bin.Debug" or "..\..\..\bin.Release" and write the number of "..\" the way all projects get the same physical output directories, somewhere on some directory parent to all project directories.

This is actually the best solution configuration even if you never use dynamic DLL loading. You see, by default, Visual Studio creates separate output directories, but output of the dependency projects is copied to dependent project's output; this creates multiple copies of executable modules and other things, which is somewhat wasteful. Visual Studio does it just to provide its "works immediately" quality, but it is not the best for well-tuned solution.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900