Using Assembly.Load(byte[]) to load multiple versions of dll, and AppDomain.AssemblyResolve

S

Stephen Ahn

Using dotnet 1.1, sp1, C#.

I have assembly "A", which references assembly "B". Neither of these
assemblies are stongly named.
I have an application which uses a plug in architecture, to load assembly
"A" using Assembly.Load(byte[]).

The app (actually a web service) needs to be able to have loaded multiple
versions of assembly "A" at the same time. eg. assembly "A" version 1, and
assembly "A" version 2. The directory structure looks like this :

-- Application's bin directory
-- v1 subdirectory (contains "A" version 1, and "B" version X).
-- v2 subdirectory (contains "A" version 2, and "B" version Y).

i.e. "A" version 1 should use "B" version X, and
"A" version 2 should use "B" version Y.

Both versions are loaded into the same AppDomain (The application's current
AppDomain). Assembly.Load(byte[]) is being used to load the versions of
assembly "A". This works fine.

My problems start when the versions of assembly "A" use the
AppDomain.AssemblyResolve event to try to load the required versions of
assembly "B". Ideally, I want to use that idea that assemblies in the same
subdirectory should use each other at runtime. There does not seem to be
enough information from inside the AppDomain.AssemblyResolve event to work
out which subdirectory's "B" to load.

Any ideas ?
eg. Load different versions of "A" into different AppDomains, make assembly
B version numbers more closely coupled with assembly "A"s version numbers ?

TIA,
Stephen
 
D

David Levine

The AssemblyResolve event only tells you what the requested assembly
identity was, not the identity of the assembly that initiated the bind (that
would have been nice to have, but oh well).

One solution: sign all the assemblies with a strong name (I believe v2.0
requires this anyway). This will establish strong binding requirements for
each assembly, so that A v1.0 will always ask for the version of B that it
was built with, (e.g. v2.3). and A v2.0 will ask for its own version B (eg
v3.4)/ You wont have to use an arbitrary versioning protocol to guess which
version of B needs to be loaded - just load the assembly requested in the
AssemblyResolve event.
 

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