Search code examples
c#.netdll.net-assemblymethodinfo

Get Assembly of program from a DLL


I would like to access a function of a program from which is attached a DLL.

In DLL I've tried:

Assembly assembly = Assembly.GetExecutingAssembly();
Type type = assembly.GetType("Uranium");
MethodInfo methodInfo = type.GetMethod("Util");

methodInfo.Invoke("SendClient", new object[] { Packet.GetData()});

But not works I get a null exception but not say the line. The running program is called and namespace is 'Uranium', the class is 'Util' and function is 'SendClient'.


Solution

  • I have been able solve it on my own.

    Code:

    Assembly assembly = Assembly.LoadFrom("Uranium.exe");
    Type type = assembly.GetType("Uranium.Util");
    MethodInfo methodInfo = type.GetMethod("SendClient");
    
    methodInfo.Invoke(null, new object[] { Packet.GetData() });