Gettype problem when invoked from a different project

J

Jennyfer Barco

Hello I have a question. I have a project called "Primary" and in that
project I have a reference to a Com application called "engine". In "engine"
I have a function that does many things and calls other local functions for
several purposes. In one of those functions I have the code:



Dim myType As Type

Application_AssemblyName = "Primary"

Nameclass = "inventory"

Namemethod ="product"



myType = Type.GetType(Application_AssemblyName & "." &
nameclass)

MyObject = CreateInstance(myType)

myMethodInfo = myType.GetMethod(namemethod)



The class "inventory" exists in the "Primary" project but it looks like
because this code is in the "engine" project, the Type.GetType returns null.
If I put this code in any function in the "Primary" project it works. How
can I solve this problem? It looks like I have to do something additional.



Thanks in advance

Jennyfer
 
H

Herfried K. Wagner [MVP]

Jennyfer,

Jennyfer Barco said:
Hello I have a question. I have a project called "Primary" and in that
project I have a reference to a Com application called "engine". In
"engine" I have a function that does many things and calls other local
functions for several purposes. In one of those functions I have the code:

Dim myType As Type

Application_AssemblyName = "Primary"

Nameclass = "inventory"

Namemethod ="product"



myType = Type.GetType(Application_AssemblyName & "." &
nameclass)

MyObject = CreateInstance(myType)

myMethodInfo = myType.GetMethod(namemethod)

The class "inventory" exists in the "Primary" project but it looks like
because this code is in the "engine" project, the Type.GetType returns
null. If I put this code in any function in the "Primary" project it
works. How can I solve this problem? It looks like I have to do something
additional.

You will have to pass the assembly-qualified type name to 'Type.GetType' if
the type is part of another assembly. The snippet below demonstrates how to
determine the assembly-qualified name of a type and creates a 'Type' object
based on the type name:

\\\
MsgBox( _
Type.GetType( _
GetType( _
System.Windows.Forms.Button _
).AssemblyQualifiedName _
) Is Nothing _
)
///

Prebuilt helper routines which will make finding the assembly-qualified type
name and instantiation easier:

<URL:http://dotnet.mvps.org/dotnet/code/codingtechnique/#ClassByName>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top