Hi
I have the following procedure
private static IMyInterface OpenInstance(
string assemblyPath,
string classType,
string assemblyName,
out AppDomain domainInstall)
{
IMyInterface interface = null;
AppDomainSetup domaininfo = new AppDomainSetup();
domaininfo.ApplicationBase = assemblyPath;
domainInstall = AppDomain.CreateDomain("PathInstall", null, domaininfo);
ObjectHandle handleService = null;
try
{
handleService = Activator.CreateInstance(
domainInstall,
assemblyName,
classType,
true,
System.Reflection.BindingFlags.CreateInstance,
null,
new Object[] { assemblyName},
System.Globalization.CultureInfo.CurrentCulture,
null, null);
Object myobject = handleService.Unwrap();
interface = (IMyInterface )myobject ;
}
catch (Exception ex)
{
...
}
return interface ;
}
This procedure works ever fine, but when it is called during an installation custom action.
In other words if i call my OpenInstance(...) procedure inside my own Install(...) override:
public override void Install(IDictionary stateServer)
Defined in my Installer extended class:
[RunInstaller(true)]
public class SpheresServiceInstaller : Installer
I got an exception when i try to cast my unwrapped object to the desired type:
interface = (IMyInterface)myobject ;
Exception details:
- Type: System.InvalidCastException
- Message: Unable to cast transparent proxy to type 'IMyInterface'.
I would like to understand why the procedure works ever but in this specific case.
Details
I followed step by step the object creation procedure and everything seems fine, the object is well created by the Activator.CreateInstance procedure.
The assembly, which is used by the Activator.CreateInstance, already exists on the file system.
The specific assembly 'assemblyName on the source code) is a window service that has been just created by the installation procedure.