470,596 Members | 1,594 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,596 developers. It's quick & easy.

Reflection - Loading assemblies with unloaded references

I have the predicament of having to load several assemblies on the fly and
when I do so, I get an exception stating that one of the referenced
assemblies cannot be found. Is there any way to recurse into an assembly to
discover the referenced assemblies without actually loading the root assembly
where I start the load?
For example:

assembly 1 contains references to assembly 1_1 and assembly 1_2
assembly 1_1 contains reference to assembly 2
assembly 1_2 contains reference to assembly 3

If I attempt to load assembly 1 in order to get the AssemblyNames[] of it's
referenced assemblies, I get an exception on the Load() call because the
referenced assemblies cannot be found. I have them all in the same directory,
by the way.
Apr 3 '06 #1
2 2458
To my knowledge no.. But what you can do is handle the missing assembly
exception and try to locate the assembly, copy it to the path, and start
your code. Also remember that .. the search path, current executable path,
GAC and so on.. You can alter this with App.Config / make it search in a
specific path for your dll's. If you still have the assembly in the same
path and getting the error.. , you might want to check the complete
reference hierarchy out.. There must be something broken in the chain, you
could also use stacktrace in the exception to examine any possible breaks in
reference.

HTH
VJ
"jnick" <jn***@discussions.microsoft.com> wrote in message
news:94**********************************@microsof t.com...
I have the predicament of having to load several assemblies on the fly and
when I do so, I get an exception stating that one of the referenced
assemblies cannot be found. Is there any way to recurse into an assembly
to
discover the referenced assemblies without actually loading the root
assembly
where I start the load?
For example:

assembly 1 contains references to assembly 1_1 and assembly 1_2
assembly 1_1 contains reference to assembly 2
assembly 1_2 contains reference to assembly 3

If I attempt to load assembly 1 in order to get the AssemblyNames[] of
it's
referenced assemblies, I get an exception on the Load() call because the
referenced assemblies cannot be found. I have them all in the same
directory,
by the way.

Apr 3 '06 #2
There's an AssemblyResolve event off of the AppDomain class that could help...

Something like:
AppDomain.CurrentDomain.AssemblyResolve += new
ResolveEventHandler(CurrentDomain_AssemblyResolve) ;

then:

private Assembly CurrentDomain_AssemblyResolve(object sender,
ResolveEventArgs args)
{
return Assembly.LoadFrom(fileName);

}

Granted you'll probably need some logic to locate/load the appropriate
library from the event handler method.

"Vijay" wrote:
To my knowledge no.. But what you can do is handle the missing assembly
exception and try to locate the assembly, copy it to the path, and start
your code. Also remember that .. the search path, current executable path,
GAC and so on.. You can alter this with App.Config / make it search in a
specific path for your dll's. If you still have the assembly in the same
path and getting the error.. , you might want to check the complete
reference hierarchy out.. There must be something broken in the chain, you
could also use stacktrace in the exception to examine any possible breaks in
reference.

HTH
VJ
"jnick" <jn***@discussions.microsoft.com> wrote in message
news:94**********************************@microsof t.com...
I have the predicament of having to load several assemblies on the fly and
when I do so, I get an exception stating that one of the referenced
assemblies cannot be found. Is there any way to recurse into an assembly
to
discover the referenced assemblies without actually loading the root
assembly
where I start the load?
For example:

assembly 1 contains references to assembly 1_1 and assembly 1_2
assembly 1_1 contains reference to assembly 2
assembly 1_2 contains reference to assembly 3

If I attempt to load assembly 1 in order to get the AssemblyNames[] of
it's
referenced assemblies, I get an exception on the Load() call because the
referenced assemblies cannot be found. I have them all in the same
directory,
by the way.


Apr 3 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Jozsef Bekes | last post: by
8 posts views Thread by Eyeawanda Pondicherry | last post: by
6 posts views Thread by Pete Davis | last post: by
1 post views Thread by Bob | last post: by
4 posts views Thread by Doug Handler | last post: by
4 posts views Thread by =?Utf-8?B?VzFsZDBuZTc0?= | last post: by
8 posts views Thread by =?Utf-8?B?TWFyaw==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.