Philipp Spiess
Philipp Spiess

Reputation: 3271

Get type of an assembly loaded in a new AppDomain

I'm using this method to create the object I want to.

The constructor of the object is successfully called.

Now, I want to call a method via reflection, but as I found out, I need to know the type. And when I do something like

Type type = Type.GetType(this.typeName);

type is null.

So, what I need to know is: How do I get the type of an assembly loaded in a new AppDomain?

Upvotes: 2

Views: 1824

Answers (3)

Philipp Spiess
Philipp Spiess

Reputation: 3271

Here is how i solved the problem: I created an interface, and used typeof(MyInterface) to work arround.

I hope this could help you.

Upvotes: 0

Jayprakash S T
Jayprakash S T

Reputation: 243

System.type type object is an object by itself and has a type object pointer member in it, and it’s member refers to itself because the System.Type type object is itself an “instance” of a type object. And System.Object’s GetType method returns the address stored in the specified object’s type object pointer member. In other words the GetType method returns a pointer to an object’s type object, and this is how you can determine the true type of any object in the system.

Use System.Reflection.AssemblyName is an utility class which gives you complete details of an assembly's unique identity in full. Use GetType method of this Class to know the type of the Assembly loaded.

http://msdn.microsoft.com/en-us/library/system.object.gettype.aspx

Upvotes: 0

Tomislav Markovski
Tomislav Markovski

Reputation: 12346

You need to use the full assembly qualified name, so you can recreate it with Type.GetType()

this.typeName = typeof(MyClass).AssemblyQualifiedName;

Without this, the executing assembly will be searched for the type which doesn't always contain your type.

Upvotes: 3

Related Questions