all groups > dotnet clr > august 2004 >
You're in the

dotnet clr

group:

class definiton if different dll's



class definiton if different dll's darek NO[at]SPAM m-core.pl
8/25/2004 1:53:11 AM
dotnet clr: Hello.

I'm wondering is it possible to have excatly the same class
definied in different assebmlies and still be able to load all of them?
Let's say that I have assebly that contains definiton of a class
and the other one which also defines excatly the same class.
During program executions I load them by System.Reflections.
Will the objects created from the first assebmly considered
as being of the same type as objects created by the other one?

I'm asking this because I would like to have 2 separate
assemblies which would be loaded by my main app, those two assemblies
should be able to exchange objects between themselvs (my apllication
is go-between of this process ). I don't want the class of objects exchanged
to be known to main app, I would also prefer not to create the thrid
assembly conatining definiton of objects shared by the assemblies.

Will it work?

--
Re: class definiton if different dll's Jon Skeet [C# MVP]
8/25/2004 9:58:25 AM
[quoted text, click to view]

No. Indeed, I believe you could even load the very same assembly twice
(in some ways) and end up with two different sets of types.

[quoted text, click to view]

No - you have to create the third assembly, basically.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
Re: class definiton if different dll's rbyers NO[at]SPAM online.microsoft.com (
8/31/2004 4:55:42 PM
You can't do this because the identity ("name") of a class includes the
identity of the assembly it was loaded from. This is absolutely essential
for component development (and avoiding "dll hell").

Even if you could trick the CLR somehow, you really wouldn't want to do
this. It's a fundamental tennant of good OO-design that all communication
is done through mutually agreed upon interfaces ("contracts"). The
definition of the interface must be unique. If you duplicated the
interface in each of the two assemblies, then there would be nothing to
ensure that the two components were talking the same language. If you
really want this amount of loose coupling (and therefore the possibility of
failure at every interaction), the way to get it is to access the object
only through reflection ("late binding").

Rick

--
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------

[quoted text, click to view]
AddThis Social Bookmark Button