Code excerpt:
var a = Assembly.LoadFile("MyAssembly.dll");
var t = a.GetType("MyNamespace.MyClass", false);
Debug.Assert(t != null); // fails
Assembly.LoadFile()
is loading the assembly without any trouble, but Assembly.GetType()
is returning null, even though I have verified that MyNamespace.MyClass
is present and correctly spelled.
Any other ideas why this is happening?
GetType(String, Boolean) Gets the Type object with the specified name in the assembly instance and optionally throws an exception if the type is not found.
The most basic way to do reflection is to use the GetType() method, but we can also use reflection to get information about methods, constructors, properties, and more.
Use Type. GetType to get the Type objects from an assembly that is already loaded.
In the line
var t = a.GetType("MyNamespace.MyClass", false);
set that boolean to true
so you get an exception that could explain the problem. For various problem situations you get separate exceptions, see MSDN or the new docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With