Assembly.GetType returns null while using C# Console Application (.NET Framework)

44 Views Asked by At

Why does Assembly.GetType(name) return null when I use C# Console Application (.NET Framework), but not when I use C# Console Application? The code works perfectly when I use C# Console Application.

Following is the code:

    Assembly myAssembly = Assembly.LoadFile(@"C:\MyFolder\MyDLL.dll");
    Type myType = myAssembly.GetType("MyDLL.MyClass");
    MethodInfo myMethod = myType.GetMethod("MethodInDLL");

The code errors at the second line with the error - System.IO.FileNotFoundException:'Could not load file or assembly 'System.Runtime, Version=4.2.2.0,Culture=neutral,PublicKeyToken=b03a6g11e6b' or one of its dependencies. The system cannot find the file specified.

The DLL I am trying to invoke is a simple one that prints a message box. Here's what it looks like:

    using System;
    using System.Windows.Forms;
    namespace MyDLL
     {
       public class MyClass
        {
          public static void MethodInDLL()
           {
             MessageBox.Show("Message from DLL file");
           }
        }
    }

The .NET version I use is 4.7.2

0

There are 0 best solutions below