I am trying to do the following :
private static MyClass CreateMyClassInDomain(ApplicationDomain domain, string componentName, params object[] parmeters)
{
var componentPath = Assembly.GetAssembly(typeof(MyClass)).CodeBase.Substring(8).Replace("/", @"\");
ObjectHandle inst = Activator.CreateInstanceFrom(domain, componentPath, "MyNsp." + componentName, true, BindingFlags.Default, null,
parmeters, null, null);
return (MyClass)inst.Unwrap();
}
Is there anything I do wrong? I the creation succeed but after when I try to use the instance of MyClass in some cases i have unexpected exception.
Edited :
Found the source of the problem , I have been using dll that I loaded in current app domain
to create instance from in other app domain and it caused inconsistency
Thank you.
Check the sample code to load an object in a different domain and execute the work.
You can only load the object in different object if that component dll is referenced in application.
If it’s not referenced then go for reflection.