Unhandled Exception: System.IO.FileLoadException: The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)
I am getting an exception from C# in a simple program consisting of two classes, Program.cs and AnotherClass.cs. I want to use the static Type.GetType
method in Program.cs to get AnotherClass
as a class when given as a string for a more complex program. When I use the following code
class Program
{
static void Main(string[] args)
{
Assembly a = Assembly.GetExecutingAssembly();
//Console.WriteLine(a.FullName);
Type t = Type.GetType($"SmallTestingSimulator.{a.FullName}.AnotherClass");
Console.WriteLine(t.Name);
}
}
and an empty class in a different file but same namespace
class AnotherClass {
}
I get the error. How do I go about using Type.GetType() for another class in this project? Without using the assembly, it gives a NullReferenceException.
Related Questions