?
Solved

How can I modify assembly search path from the code?

Posted on 2007-07-24
4
Medium Priority
?
343 Views
Last Modified: 2012-08-13
Dear expert.
I have a C# assembly module.dll that has a reference to C# submodule.dll.
module.dll has a public class module.ClassInvoker that has a public static method Invoke.
Method Invoke uses code from submodule.dll.
Both of the modules are located in D:\DOTNETSamlpe\lib.

I have DOT net application that has no reference to module.dll and calls to method dynamically:
System.Reflection.Assembly asm = System.Reflection.Assembly.LoadFile(""D:\\DOTNETSamlpe\\lib\\module.dll"");
 System.Type classType = asm.GetType("module.ClassInvoker");
 System.Reflection.MethodInfo  methodInfo = classType.GetMethod("Invoke");  
 methodInfo.Invoke(null, null);

This code works only if exe is located in D:\DOTNETSamlpe\lib  the same folder where module.dll and submodule.dll are located.

If exe is not located in D:\DOTNETSamlpe\lib methodInfo.Invoke(null, null) throws exeption. I see that inner exception is Could not load file or assembly 'submodule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.":"submodule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

I suspect that the problem is that the search path doesnt match in D:\DOTNETSamlpe\lib.
How can I modify assembly search path from the code?
Thanks.
0
Comment
Question by:netformx
  • 2
  • 2
4 Comments
 
LVL 18

Expert Comment

by:DarrenD
ID: 19554579
Hi,

Can you install the assemblies in the GAC? Then the would be found.

Just a thought.

Darren
0
 

Author Comment

by:netformx
ID: 19554738
No.
I want it work when it is not located in GAC.
0
 
LVL 18

Accepted Solution

by:
DarrenD earned 2000 total points
ID: 19554769
hi,

What about trying to use LoadFrom instead of LoadFile.

What version of .NET are you using?

Just another thought.

Darren
0
 

Author Comment

by:netformx
ID: 19554899
Thank a lot
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

850 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