I need to get an instance of a type whose name and assembly name I will have at runtime. I know in advance the type will have a parameterless constructor. What's the easiest way to do this?
It's waaaaaaay harder than I was hoping it would be.
Edit: I'm not if this is relevant, but the assembly will be referenced. I don't need to load it from disk or something.
Loads an assembly given its AssemblyName. The assembly is loaded into the domain of the caller using the supplied evidence. Loads the assembly with a common object file format (COFF)-based image containing an emitted assembly. The assembly is loaded into the application domain of the caller.
Use Type. GetType to get the Type objects from an assembly that is already loaded.
Type.GetType(string.Concat(typeName, ", ", assemblyName))
http://msdn.microsoft.com/en-us/library/w3f99sx1.aspx http://msdn.microsoft.com/en-us/library/system.type.assemblyqualifiedname.aspx
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