AppDomain Casting

G

Guest

AppDomain appDomain = AppDomain.CreateDomain("appDomain", null, null);
try
{
appDomain.AppendPrivatePath(@"C:\DLLS\");
appDomain.Load(@"FF-DeliousDateTimeRequestor");

ObjectHandle o = appDomain.CreateInstance("FF-DeliousDateTimeRequestor",
"DeliousTools.Loader");
object ob = o.Unwrap();
IDeliousToolsInt obj = (IDeliousToolsInt)ob;
obj.Start();
}
finally
{
AppDomain.Unload(appDomain);
}

Does anyone know how to solve this exception:

An unhandled exception of type 'System.InvalidCastException' occurred in
NewerDeliousLauncher.exe

Additional information: Specified cast is not valid.

The error occurs in this line:
IDeliousToolsInt obj = (IDeliousToolsInt)ob;

Thank you in advance!
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,


Does anyone know how to solve this exception:

An unhandled exception of type 'System.InvalidCastException' occurred in
NewerDeliousLauncher.exe

Additional information: Specified cast is not valid.

The error occurs in this line:
IDeliousToolsInt obj = (IDeliousToolsInt)ob;

Put a breakpoint in the line above, what type is reported?

Is your IDeliousToolsInt the very same interface than the one you are
creating?

My bet is that you define the same interface in two different places, if you
did you cannot cast one to other as they are differents.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top