Type.GetType () dynamic string returns null

I am using Type.GetType() to instantiate.

It works:

  var type = Type.GetType("Test.ClassServices.HowService, Test"); 

But that does not work. It returns null :

  var name = "How"; var type = Type.GetType("Test.ClassServices."+name+"Service, Test"); 
+6
source share
1 answer

No reproduction. Run this sample:

 var hardCodedWorking = Type.GetType("System.String"); var stringName = "String"; var concatenatedWorking = Type.GetType("System." + stringName); var badStringName = "string"; var concatenatedNull = Type.GetType("System." + badStringName); 

From Type.GetType () on MSDN:

Returns the type with the specified name using case-sensitive search.

Based on this and my example above, I believe that most likely the value of name does not match the class name perfectly.

+5
source

Source: https://habr.com/ru/post/913051/


All Articles