1 Replies - 429 Views - Last Post: 27 June 2019 - 04:09 AM Rate Topic: -----

#1 RushabhVerma   User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 13
  • Joined: 23-April 19

Why does Type.GetType not return a Type when given an input the exact

Posted 26 June 2019 - 09:50 PM

Let's say I have a project containing a large collection of subclasses and I want to interrogate them on the fly.

Given a full namespace and class name:

 SomeCompany.SomeProduct.Data.Sample.Client.clsName


In my test class I have the following:

string fullClassName = typeof(SomeCompany.SomeProduct.Data.Sample.Client.clsName).FullName;
    // returns "SomeCompany.SomeProduct.Data.Sample.Client.clsName"

    Type classType = Type.GetType("SomeCompany.SomeProduct.Data.Sample.Client.clsName");
    // throws an error or with false for error reporting returns null


How can thew same exact classnames not work? What am I missing? I'm not shortening anything with using so the full entire classname is being used and not working in both cases even though they should rationally be identical.

Is This A Good Question/Topic? 0
  • +

Replies To: Why does Type.GetType not return a Type when given an input the exact

#2 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7053
  • View blog
  • Posts: 23,975
  • Joined: 05-May 12

Re: Why does Type.GetType not return a Type when given an input the exact

Posted 27 June 2019 - 04:09 AM

Read the documentation. You are supposed to pass in the assembly qualified name. You are using FullName.

Quote

typeName
String
The assembly-qualified name of the type to get. See AssemblyQualifiedName. If the type is in the currently executing assembly or in Mscorlib.dll, it is sufficient to supply the type name qualified by its namespace.

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1