I'm trying to call
Type.GetType("System.Diagnostics.TraceFilter")
not typeof(System.Diagnostics.TraceFilter)
but the result is always null. Could anyone help me out? How to get class type for this abstract class?
I'm trying to call
Type.GetType("System.Diagnostics.TraceFilter")
not typeof(System.Diagnostics.TraceFilter)
but the result is always null. Could anyone help me out? How to get class type for this abstract class?
It's probably because you must provide an assembly-qualified name.
Better, though, would be to use this instead:
typeof(System.Diagnostics.TraceFilter)
From the documentation for Type.GetType(string typeName)
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.
The type you are fishing around for (i.e. "System.Diagnostics.TraceFilter") is not in the currently executing assembly or in "Mscorlib.dll", it is in fact in "System.dll". Therefore you have to use the fully qualified assembly name, e.g.:
Type type = Type.GetType("System.Diagnostics.TraceFilter, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
Alternatively you can use:
Type type = typeof(System.Diagnostics.TraceFilter);
According to MSDN, Type.GetType(string) requires an assembly-qualified name unless the target type is either in the currently executing assembly or mscorlib.dll. System.Diagnostics.TraceFilter is in System.dll, which means that you must use an assembly-qualified name.