How to call a non-static method in different assembly using Reflection in C# and VB.NET

To call a static method in different assembly using Reflection in C# and VB.NET you can use the snippet below.

Sample C#

Assembly assembly = Assembly.LoadFile(@"Assembly_Location");   
var type = assembly.Types().FirstOrDefault(x => x.FullName.Contains("MyClassName"));
var constructor = type.GetConstructor(Type.EmptyTypes);

var classObject = constructor.Invoke(new object[] { }); //call parameterless constructor
var classObject = constructor.Invoke(new object[] { param1 }); //call non-parameterless constructor

MethodInfo methodInfo = type.GetMethod("MyMethodName");
methodInfo.Invoke(classObject, new object[] { }); //pass classobject, parameterless method
methodInfo.Invoke(classObject, new object[] { param1 }); //pass classobject, parameterized method

Sample VB.NET

Dim assembly__1 As Assembly = Assembly.LoadFile("Assembly_Location")
Dim type__2 = assembly__1.Types().FirstOrDefault(Function(x) x.FullName.Contains("MyClassName"))
Dim constructor = type__2.GetConstructor(Type.EmptyTypes)

Dim classObject = constructor.Invoke(New Object() {})'call parameterless constructor
Dim classObject = constructor.Invoke(New Object() {param1})'call non-parameterless constructor

Dim methodInfo As MethodInfo = type__2.GetMethod("MyMethodName")
methodInfo.Invoke(classObject, New Object() {})'pass classobject, parameterless method
methodInfo.Invoke(classObject, New Object() {param1})'pass classobject, parameterized method

How to call a static method in different assembly using Reflection in C# and VB.NET

To call a static method in different assembly using Reflection in C# and VB.NET you can use the snippet below.

Sample C#

Assembly assembly = Assembly.LoadFile(@"Assembly_Location"); 
var t = assembly.Types().FirstOrDefault(x=>x.FullName.Contains("MyClassName"));
var method = t.GetMethod("MyMethodName", BindingFlags.Public | BindingFlags.Static);
method.Invoke(null, null); //assuming that the method does not have parameters
method.Invoke(null, new object[] { param1}); //assuming that the method has 1 parameter

Sample VB.NET

Dim assembly__1 As Assembly = Assembly.LoadFile("Assembly_Location")
Dim t = assembly.Types().FirstOrDefault(Function(x) x.FullName.Contains("MyClassName"))
Dim method = t.GetMethod("MyMethodName", BindingFlags.[Public] Or BindingFlags.[Static])
method.Invoke(Nothing, Nothing) 'assuming that the method does not have parameters
method.Invoke(Nothing, New Object() {param1}) 'assuming that the method has 1 parameter

How to get the name of the calling method in C# and VB.NET

To get the name of the calling method in C# and VB.NET you can use the snippet below.

Sample C#

public static string GetCallingMethodName()
{
	var stackTrace = new StackTrace();
	return stackTrace.GetFrame(1).GetMethod().Name;
}

Sample VB.NET

Public Shared Function GetCallingMethodName() As String
	Dim stackTrace = New StackTrace()
	Return stackTrace.GetFrame(1).GetMethod().Name
End Function

How to get the Calling Assembly in C# or VB.NET

To get the Calling Assembly in C# or VB.NET you can use Reflection.

Sample C#

using System.Reflection;

public static string GetCallingAssemblyName()
{
var callingAssembly = Assembly.GetCallingAssembly();
return callingAssembly.FullName;
}

Sample VB.NET

Imports System.Reflection

Public Shared Function GetCallingAssemblyName() As String
    Dim callingAssembly = Assembly.GetCallingAssembly()
    Return callingAssembly.FullName
End Function

for more informations see the MSDN: Reflection (C# and Visual Basic), Assembly.GetCallingAssembly Method