string assemblyFile = "MyAssembly.dll"; string typeName = "MyNamespace.MyClass"; string assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); AppDomain appDomain = AppDomain.CreateDomain("MyAppDomain"); object obj = appDomain.CreateInstanceFromAndUnwrap(Path.Combine(assemblyPath, assemblyFile), typeName); MethodInfo method = obj.GetType().GetMethod("MyMethod"); method.Invoke(obj, null);
string assemblyFile = "MyAssembly.dll"; string typeName = "MyNamespace.MyClass"; string assemblyPath = @"C:\MyDirectory"; AppDomain appDomain = AppDomain.CreateDomain("MyAppDomain"); object obj = appDomain.CreateInstanceFromAndUnwrap(Path.Combine(assemblyPath, assemblyFile), typeName);This example creates an instance of type MyClass from the MyAssembly.dll file located in the C:\MyDirectory folder. Package library: System.Reflection Namespace: System.Reflection.Emit Note: To execute the example code, make sure to add the necessary namespaces and assembly references.