Hello,
I have the requirement of being able to load different versions of the same
type (same class name) in the executing AppDomain. I am aware that I would
not be able to unload obsolete instances, but I don't mind. The problem is
that, it seems, only one instance of the same class type can be present in
one particular AppDomain, and whatever attempt to load a class with the same
name will result in the old instance being passed.
I would assume that a possible solution would be to have class names get
different names (eg. SampleClassName_{some Guid}) before being loaded, but
can I really do this hacking into a compiled DLL?
I have Googled around but couldn't find anything related to this. Any ideas?
Thanks in advance, regards,
Vanni
Ignacio Machin ( .NET/ C# MVP ) - 09 Oct 2007 18:01 GMT
Hi,
> Hello,
>
[quoted text clipped - 6 lines]
> same
> name will result in the old instance being passed.
You can only have one type per AppDomain, otherwise how the compiler can
determine which version to use when you use a new statement:
object o = new XXXX
Why you have to load it in the same AppDomain? I guess you could load it in
a different AppDomain. But even so how you are going to know what features
provide each version?
Nicholas Paldino [.NET/C# MVP] - 09 Oct 2007 18:09 GMT
Vanni,
You can do this, but you have to know at compile time what the two
separate versions are. You would use the "extern alias" keywords, along
with a special way of referencing the dlls which contain the types when
calling the compiler (there is support in VS.NET for this too).
Take a look at the documentation for "extern alias" located at:
http://msdn2.microsoft.com/en-us/library/ms173212(VS.80).aspx
Anson Horton also has a walkthrough which will help:
http://blogs.msdn.com/ansonh/archive/2006/09/27/774692.aspx

Signature
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
> Hello,
>
[quoted text clipped - 16 lines]
> Thanks in advance, regards,
> Vanni
Vanni - 09 Oct 2007 19:34 GMT
Hi Nicholas,
Thanks to you and all those who replied.
The extern alias solution matches my requirement very, very closely, that
sounds excellent news!
However, how would I be able to specify aliasing when loading the two
different DLL's in the AppDomain?
Thanks,
V.
> Vanni,
>
[quoted text clipped - 31 lines]
> > Thanks in advance, regards,
> > Vanni
Jon Skeet [C# MVP] - 09 Oct 2007 18:52 GMT
> I have the requirement of being able to load different versions of the same
> type (same class name) in the executing AppDomain. I am aware that I would
[quoted text clipped - 8 lines]
>
> I have Googled around but couldn't find anything related to this. Any ideas?
Are you trying to do this by dynamically loading the DLLs, or do you
need to do it at compile time? At compile time you can use "extern
aliases" - at execution time it's somewhat different, due to the
mucking around with reflection.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too