473,386 Members | 1,720 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,386 software developers and data experts.

obtain ref to assembly from created class instance

It does not seem possible to compare instances of assemblies from which
instances of controls/classes are created.

In other words, if I have

Assembly myAssembly Assembly.LoadFrom(path);
object myClass = myAssembly.CreateInstance("<ClassName>");

It is not possible to obtain a reference to myAssembly from myClass ...

Jun 20 '07 #1
7 1394
On Jun 19, 4:58 pm, "John Grandy" <johnagrandy-at-gmail-dot-com>
wrote:
It does not seem possible to compare instances of assemblies from which
instances of controls/classes are created.

In other words, if I have

Assembly myAssembly Assembly.LoadFrom(path);
object myClass = myAssembly.CreateInstance("<ClassName>");

It is not possible to obtain a reference to myAssembly from myClass ...
How about

Assembly a = myClass.GetType().Assembly;

?

Jun 20 '07 #2
I wonder if myClass.GetType().Assembly returns the assembly instance from
which the object was created ( via Assembly.CreateInstance() ), or if it
returns a new instance of the assembly associated with the object's type.

In other words, if two class instances were created respectively from two
instances of the same assembly, then does

myClass1.GetType().Assembly == myClass2.GetType().Assembly

return true or false ?
"Bruce Wood" <br*******@canada.comwrote in message
news:11**********************@n15g2000prd.googlegr oups.com...
On Jun 19, 4:58 pm, "John Grandy" <johnagrandy-at-gmail-dot-com>
wrote:
>It does not seem possible to compare instances of assemblies from which
instances of controls/classes are created.

In other words, if I have

Assembly myAssembly Assembly.LoadFrom(path);
object myClass = myAssembly.CreateInstance("<ClassName>");

It is not possible to obtain a reference to myAssembly from myClass ...

How about

Assembly a = myClass.GetType().Assembly;

?

Jun 21 '07 #3
<"John Grandy" <johnagrandy-at-gmail-dot-com>wrote:
I wonder if myClass.GetType().Assembly returns the assembly instance from
which the object was created ( via Assembly.CreateInstance() ), or if it
returns a new instance of the assembly associated with the object's type.

In other words, if two class instances were created respectively from two
instances of the same assembly, then does

myClass1.GetType().Assembly == myClass2.GetType().Assembly

return true or false ?
True, always - and GetType() will always return the same Type reference
too.

--
Jon Skeet - <sk***@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
Jun 22 '07 #4
Is there any other way to test whether two instances of a class were created
from different instances of the same assembly type ? Or do class instances
not have "memory" of how they were created ?

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP*********************@msnews.microsoft.com. ..
<"John Grandy" <johnagrandy-at-gmail-dot-com>wrote:
>I wonder if myClass.GetType().Assembly returns the assembly instance from
which the object was created ( via Assembly.CreateInstance() ), or if it
returns a new instance of the assembly associated with the object's type.

In other words, if two class instances were created respectively from two
instances of the same assembly, then does

myClass1.GetType().Assembly == myClass2.GetType().Assembly

return true or false ?

True, always - and GetType() will always return the same Type reference
too.

--
Jon Skeet - <sk***@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

Jun 22 '07 #5
<"John Grandy" <johnagrandy-at-gmail-dot-com>wrote:
Is there any other way to test whether two instances of a class were created
from different instances of the same assembly type ? Or do class instances
not have "memory" of how they were created ?
No, they do:

if (a.GetType() != b.GetType())

will compare the types including which assemblies they were loaded
from.

--
Jon Skeet - <sk***@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
Jun 22 '07 #6
Here is what I'm finding in practice :
Assembly assembly1 = Assembly.LoadFrom( assemblyPath );

Assembly assembly2 = Assembly.LoadFrom( assemblyPath );

object instance1 = assembly1.CreateInstance( className );

object instance2 = assembly2.CreateInstance( className );

Assert.IsTrue( instance1.GetType() == instance2.GetType(), "Assert.IsTrue:
instance1.GetType() == instance2.GetType()" );

The assert does not throw an exception.

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP*********************@msnews.microsoft.com. ..
<"John Grandy" <johnagrandy-at-gmail-dot-com>wrote:
>Is there any other way to test whether two instances of a class were
created
from different instances of the same assembly type ? Or do class
instances
not have "memory" of how they were created ?

No, they do:

if (a.GetType() != b.GetType())

will compare the types including which assemblies they were loaded
from.

--
Jon Skeet - <sk***@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

Jun 22 '07 #7
<"John Grandy" <johnagrandy-at-gmail-dot-com>wrote:
Here is what I'm finding in practice :
Assembly assembly1 = Assembly.LoadFrom( assemblyPath );

Assembly assembly2 = Assembly.LoadFrom( assemblyPath );

object instance1 = assembly1.CreateInstance( className );

object instance2 = assembly2.CreateInstance( className );

Assert.IsTrue( instance1.GetType() == instance2.GetType(), "Assert.IsTrue:
instance1.GetType() == instance2.GetType()" );

The assert does not throw an exception.
I suspect you'll find that assembly1==assembly2 then as well.

--
Jon Skeet - <sk***@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
Jun 23 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: David Elliott | last post by:
I am trying to load an assembly and execute a method from a class. I have listed 3 parts to the code. 1) The Driver to load and execute 2) The Interface 3) The assembly I have a valid referece...
15
by: Thomas Christmann | last post by:
Hi! I have a rather special question here. I'd like to write a wrapper for a .NET assembly, and register that on my server so that the people on my server call my assembly instead of the...
5
by: Abdul | last post by:
I am working on a .net project and need some help. The project contains different components. Each component is in its privated assembly. For e.g Component1 is a C# library project in VS.net and...
1
by: Zachary Hartnett | last post by:
I was trying to write a routine this morning that would open a given assembly, walk the inheritance tree of classes in the assembly, and provide a list of classes in the assembly that inherit from...
3
by: Steve Long | last post by:
Hello, can anybody tell me what the trick is to getting VB.NET 2003 to step into the code of an assembly that I have referenced in my project? For instance, I have these two assemblies, both...
0
by: Fred | last post by:
Hello, I am using a separate app domain to load an assembly from either disk or cache, create an instance of it and run a method. I then call dispose on the created instance and unload the app...
0
by: mschep | last post by:
Hi, I built an assembly with a set of user controls. This can be done with the Visual Studio 2005 Deployment Project: building and merging for example all your aspx and ascx in one dll (lets...
3
by: Shawnk | last post by:
I use two classes to manage the Main() command line (and alot of other stuff) for my prototyping environment. I tryed putting the MainClass in a DLL and just having the other class (which gets...
1
by: Samuel R. Neff | last post by:
I'm looping through assemblies and checking CodeBase prior to processing a given assembly. However, I occasionally get this error: The invoked member is not supported in a dynamic module. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.