Here is situation:
I have two projects. ConsoleApp and Class Library. Console app references class library.
There is Person class in Class library.
Following code returns null in type variable:
static void Main(string[] args)
{
Type type = AppDomain.CurrentDomain.GetAssemblies()
.Select(a => a.GetType("LoadTest.Person", false)).Where(t => t != null).FirstOrDefault();
}
However if I add direct declaration, code is working well.
static void Main(string[] args)
{
Person p = null;
Type type = AppDomain.CurrentDomain.GetAssemblies()
.Select(a => a.GetType("LoadTest.Person", false)).Where(t => t != null).FirstOrDefault();
}
It is known problem. However is it any solution without declaration any assembly member?
Thanks in advance.
You can simply:
that will load the assembly and give you the type you want, but if you want to use the Assembly class for some reason, do this:
or, if you do not know the type at runtime nor the dll filename but you can be sure that the dll is in the working directory you can do this: