I need to make something like:
Type CustomType = Type.GetType("instanceName");
It always returns null. instanceName is a string which represents a type contained in a dll added to References (with copyLocal property set to false).
I also tried:
Type CustomType = Type.GetType("instanceName, dllFile.dll");
But also returns null.
Thanks a lot
Alex
If the assembly is already loaded you could try this:
Type customType = Type.GetType("namespace.typename, assembly");
If you are not deploying the assembly to the GAC and the CopyLocal
setting is set to false
, then where are you planning to load the assembly from?
If you are planning to deploy the assemblies to a fixed location on a drive, you can use Assembly.LoadFrom
:
var assembly = Assembly.LoadFrom(@"C:\Path\To\Assembly.dll");
var type = assembly.GetType("InstanceName");
This allows you to load an absolute assembly. If you are using Type.GetType
, it uses the standard fusion assembly loading rules to attempt to find a matching assemby (but if it is not GAC'd or CopyLocal
= true
), then it won't be deployed with your output, and GetType
will return null.
Also, if you do not specify an assembly name in the type name, e.g. instanceName, assemblyName
, instead of instanceName
, the I believe only the currently executing assembly is checked.
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