Is there any way to get the assembly that contains a class with name TestClass
?
I just know the class name, so I can\'t create an instance of that. And
From the Type objectType
in the question, I assume you are actually after the type by name (not the assembly); so assuming the assembly is loaded and the type name is unique, LINQ may help:
Type objectType = (from asm in AppDomain.CurrentDomain.GetAssemblies()
from type in asm.GetTypes()
where type.IsClass && type.Name == "TestClass"
select type).Single();
object obj = Activator.CreateInstance(objectType);
However, it may be better to work with the assembly-qualified name instead of the type name.