Albert Gao
Albert Gao

Reputation: 3769

Could not load type from assembly

for avoiding the duplicate codes, I wrote a method, which I pass a string(ClassNameString) as parameter into it, and use it to generate 2 things, one is the a url for WebClient, and one is a Class which name is the string value.

The 1st purpose can be done without a problem, but the 2nd really bothers me, I wrote the code below.

Type targetRawDataClassType = Type.GetType( ClassNameString, true );

but the codes falis, it said "Could not load type 'ClassNameString' from assembly 'ABCDEFG, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'."

How to resolve it?

Upvotes: 3

Views: 13155

Answers (1)

Albert Gao
Albert Gao

Reputation: 3769

It seems very weird.

I solve the problem by refer the complete namespace when doing the GetType. it seems that even I have refer the namespace using "using XXXXX" at first, it doesn't work. I should refer it in runtime.

this problem has been solved via the code below:

Type targetRawDataClassType = Type.GetType(
                               NameSpaceString + 
                               ClassNameString, 
                               true );

Upvotes: 9

Related Questions