By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,780 Members | 1,523 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,780 IT Pros & Developers. It's quick & easy.

Reflection - Loading assemblies with unloaded references

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.