Type

G

Guest

I want to use a static method of a class using only the text name of the
class and the text name of the method.

The Assembly Name for this Static class is "DALLibrary"
The Namespace name for the Static Class is "GL.DAL"
The Class name of the Static class is "GL_ACCOUNT_TBL_DAL"

I tried to create a "Type" object with the following set of instructions...

string myclass = "DALLibrary.GL.DAL.GL_ACCOUNT_TBL_DAL";
Type myType = Type.GetType(myclass);

This returns "null". What is wrong with how I am constructing my "Type"?


Thanks in advance for your assistance!!
 
T

Tom Porterfield

OldButStillLearning said:
I want to use a static method of a class using only the text name of the
class and the text name of the method.

The Assembly Name for this Static class is "DALLibrary"
The Namespace name for the Static Class is "GL.DAL"
The Class name of the Static class is "GL_ACCOUNT_TBL_DAL"

I tried to create a "Type" object with the following set of instructions...

string myclass = "DALLibrary.GL.DAL.GL_ACCOUNT_TBL_DAL";
Type myType = Type.GetType(myclass);

This returns "null". What is wrong with how I am constructing my "Type"?

As it appears that GL_ACCOUNT_TBL_DAL is in a different assembly, you
need to pass the assembly qualified name to your GetType call. That
format would like similar to:

TopNamespace.SubNameSpace.ContainingClass+NestedClass, MyAssembly,
Version=1.3.0.0, Culture=neutral, PublicKeyToken=b17a5c561934e089
 
T

Tom Porterfield

OldButStillLearning said:
As my example shows, I am passing the assembly name...

And as my reply shows in comparison, you are passing it incorrectly.
Yours should look something like:

GL.DAL.GL_ACCOUNT_TBL_DAL, DALLibrary, Version=<assembly version>,
Culture=neutral, PublicKeyToken=<assembly public key>

Replace <assembly version> with the version of DALLibrary. Replace the
neutral culture with the assembly culture if it has one. Replace
<assembly public key> with the public key token for the assembly, or
null if it doesn't have one. The basic format is:

Namespace.Class, Assembly, Version, Culture, PublicKeyToken
 

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