Reputation: 6226
I am attempting to load a dll into a seperate app domain using this code:
AppDomain domain = AppDomain.CreateDomain("HardwareAbstractionLayer");
string pathToDll = @"DeviceManagement.dll";
Type t = typeof(DeviceManager);
DeviceManager myObject = (DeviceManager)domain.CreateInstanceFromAndUnwrap(pathToDll, t.FullName);
I get the error: "Constructor on type 'DeviceManagement.DeviceManager' not found."
It appears that the dll uses a singleton pattern and I'm not sure how to use the AppDomain function in that case. Here is the constructor code for the dll:
private DeviceManager() { }
private static readonly DeviceManager instance = new DeviceManager();
public static DeviceManager Instance { get { return instance; } }
Upvotes: 1
Views: 6148
Reputation: 755327
What you'll need to do is create a wrapper object to create the instance for you.
public sealed class DeviceManagerWrapper : MarshalByRefObject {
public DeviceManagerWrapper(){}
public DeviceManager DeviceManager {
get { return DeviceManager.Instance; }
}
}
Now just create an instance of DeviceManagerWrapper
and grab the DeviceManager
singleton through the property.
Upvotes: 3
Reputation: 887967
You need to make a separate entry-point class with a public constructor that has a property that returns the singleton instance.
Both classes must inherit MarshalByRefObject
.
Upvotes: 0