0

I'm using the Type.GetType function to get reflection info about a class. if I use that function from my app all works ok, but now i need to call that function from an external dll previously loaded from my app.

This code works fine if the called from the main app

Type myType1 = Type.GetType("MyNameSpace.MyType");

but fails (myType1 returns nothing) if that code is put inside of a dll (that dll is loaded from my app)

The question is how i can use Type.GetType to load a type which exist in the Exe which load the dll?

EDIT :

I think which the question can be reformulated like how i can load a type from the assembly which loads my dll?

MyEXE
  Myclass   
  MyDll (loaded by MyExe)
    Type.GetType //only get types of the MyDll assembly, how i can access the Myclass type which is defined on MyExe?
Salvador
  • 16,132
  • 33
  • 143
  • 245

2 Answers2

3

You need to use Fully Qualified Names when using DLL's outside of the project scope

Type myType1 = Type.GetType("MyType, MyNameSpace", true, true);

Give that a try

lzam
  • 185
  • 16
Blast_dan
  • 1,135
  • 9
  • 18
  • Please check the updated anwser , I really I'm using qualified names, the issue is that when I use the `Type.GetType` function only get types of the current assembly (MyDll) and i need get the type from the exe which loads the assembly. – Salvador May 22 '12 at 19:03
  • Your example says that your not using fully qualified namespace. Look at the example again to make sure your using a , to separate your class name from namespace – Blast_dan May 22 '12 at 19:05
  • Thanks very much i missed the `,` – Salvador May 22 '12 at 19:11
  • I should have used the code wrap to make it more apparent. Glad you figured it out! – Blast_dan May 22 '12 at 19:15
0

you can also load the Assemblies via the Assembly.Load Method, and then enumerate all (GetTypes()) or also get a specific type from the assembly. just take a look at the Assembly class

user287107
  • 9,286
  • 1
  • 31
  • 47