Ste Ste - 3 months ago 16
C# Question

Assembly.GetType is returning null

I am trying to dynamically load an encryption assembly but my

GetType
is returning null, even though I am using the correct class name. Here's the code:

//Load encryption assembly.
Assembly encryptionAssembly = Assembly.LoadFrom("Encryption.dll");
foreach(Type t in encryptionAssembly.GetTypes())
{
MessageBox.Show(t.Name.ToString());
// This shows "Encryption"
}
Type encryptionClass = encryptionAssembly.GetType("Encryption");
// But this returns null


I've got a bit of a headache with this one. The class is public and I've definitely spelled it correctly.

Thanks in advance.

Answer

Here

MessageBox.Show(t.FullName.ToString()); //FULLNAME

print out the FullName of the type and after use that FullName to get the type from the assembly.