Invoke and assembly references/folders

K

Kopiad

I have two assemblys A and B in folder 1. Assembly A references
assembly B.
In another folder 2, I have a program C that do a
Assmebly.LoadFile(<absolute path to assembly A) and creates an instance
of a class in A. When invoking a method (from the program C) in
assembly A that creates an instance of a class in assembly B I get a
TargetInvocationException with an inner FileNotFoundException.

The system is looking for assembly B in program Cs folder instead of
assembly As folder.
If I copy assembly B to program Cs folder it woks.

How do I make it search for the assembly in the "correct" folder?

Regards
Hans Forssell
 
M

Michael Nemtsev

Hello (e-mail address removed),

Try to use Assembly.LoadFrom instead of Assmebly.LoadFile
I have two assemblys A and B in folder 1. Assembly A references
assembly B.
In another folder 2, I have a program C that do a
Assmebly.LoadFile(<absolute path to assembly A) and creates an
instance
of a class in A. When invoking a method (from the program C) in
assembly A that creates an instance of a class in assembly B I get a
TargetInvocationException with an inner FileNotFoundException.
The system is looking for assembly B in program Cs folder instead of
assembly As folder.
If I copy assembly B to program Cs folder it woks.
How do I make it search for the assembly in the "correct" folder?

Regards
Hans Forssell
---
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
M

Michael Nemtsev

Hello (e-mail address removed),

In MSDN they do mention that LoadFile doesn't resolve dependencies as LoadFrom
does
Thanks Michael, now it works! I think the VisualStudio documentation
for the Assembly class could be more informative. Found a good
description of the problem at
http://www.gotdotnet.com/team/clr/LoadFromIsolation.aspx once I knew
what to search for.

Regards
Hans Forssell
Michael Nemtsev skrev:
---
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top