473,396 Members | 2,014 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 2608
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jozsef Bekes | last post by:
Hi All, I am trying to use reflection for getting all the classes from the dlls of a software written by my company. I am using this line: Assembly.LoadFile(s).GetTypes() Gettypes fails, I...
4
by: Jimi | last post by:
Given a C# project file path, can I use reflection to get all the assemblies referenced by the project? e.g., I know the path of a C# project, say, "c:\SomeProject.csproj", and I want to load...
8
by: Eyeawanda Pondicherry | last post by:
I have put some code together that creates an enum dynamically from some database values. The enum can be read perfectly by an application that references the dynamically generated dll. If I...
6
by: Pete Davis | last post by:
I'm confused about what precisely the limitations are on loading plugins in separate app domains. In all my previous apps that supported plugins, I've loaded them into the same domain as the app,...
1
by: Bob | last post by:
I need to be able to remotely load all referenced assemblies of an executable. The example code below works fine when all referenced assemblies are either 1. copied locally or 2. registered in the...
4
by: Doug Handler | last post by:
Ok, I think this is my last one - in my app, the user can select via a dialog box the dll's they want to load. I use a checkbox to track this (no worries there), but, once a dll has been bound,...
0
by: npthomson | last post by:
Hi all, This could get a bit complicated but I'll try to be as clear as possible. I've written an application that discovers plugins at runtime using reflection from a subdirectory of the...
4
by: =?Utf-8?B?VzFsZDBuZTc0?= | last post by:
When one architects a new project one of the first steps in the decision is to decide on the layers. (In my opinion anyway) One architecture that I have used before is to go solid OO and create...
8
by: =?Utf-8?B?TWFyaw==?= | last post by:
We've got a wierd failure happening on just one machine. One part of our product uses a 3rd party search implementation (dtSearch). DtSearch has a native core (dten600.dll), late-bound, and a...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.