Type.GetType(string)
I have working on some reflection and CodeDom stuff in .net 2.0 . My requirement was to create types at runtime by emitting in memory assemblies (i ll put the details later on) . At one place i encountered a naive and innocent looking function Type.GetType(string) . As i typed the method , intellisense popped in and suggested the usage of the method ” Get the Type with the specified name, performing a case-sensitive search.” (its in msdn), so i called the method with Type.GetType(”Font”) and to my amazement it returned. i was puzzled as i was running a winform application and Font type is one of important types in winform apps.
I looked for the remarks section in msdn , it says GetType method takes a Type name and search for it in the current assembly or mscorlib, if you supply Assembly Fully Qualified Name (AFQN), then it will load the assembly and search in it. i tried again by giving Typename, assembly name format , but i guess i made a mistake there, which led me to these pages
Type.GetType(string typeName) returns null !? by Haibo Lou
TypeName Grammar by Yiru
In summary , Type.AssemblyQualifiedName is the typename one should pass when calling Type.GetType(string) with public key token and culture. I think MS should update their documentation, so that API summary should state what it is expecting .
regards




Leave a Reply