I'd suggest calling GetType() on the type object, and then looking at
the properties to see what you really have. 

It's also really useful to run fuslogvw to see what assemblies are
getting loaded. 




-----Original Message-----
From: Oren Novotny [mailto:[EMAIL PROTECTED]] 
Sent: Tuesday, January 21, 2003 9:00 AM
To: [EMAIL PROTECTED]
Subject: [ADVANCED-DOTNET] InvalidCast with
AppDomain.CreateInstanceAndUnwrap


I'm getting a strange InvalidCastException when I try to convert the
object I get from an AppDomain.CreateInstanceAndUnwrap call.  What I'm
trying to do is create a proxy object in my own AppDomain so that I can
define my own AppBase and config file.  

Now, the assembly is loaded, and I can tell because of the constructor
outputs in the debug console, and I can get an "object" out of the
CreateAndUnwrap.  But, if I try to cast it either to the implemented
interface or even just the object itself, I get an InvalidCastException.

Any ideas?

Thanks,
--Oren


class TraceabilityAddIn : MarshalByRefObject, ITraceabilityAddIn { ... }

interface ITraceabilityAddIn { ... }


class TraceabilityAddInProxy : ITraceabilityAddIn 
{
ITraceabilityAddIn _AddIn;
void Init() {
// Get the path we're executing in
string path = new
System.IO.FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryNa
me;

AppDomainSetup setup = new AppDomainSetup(); setup.ApplicationBase =
path; setup.ApplicationName = "Traceability AddIn";
setup.ConfigurationFile = "Traceability.config";

AppDomain ad = AppDomain.CreateDomain("TraceabilityDomain" , null,
setup);

try
{
        _AddIn =
(ITraceabilityAddIn)ad.CreateInstanceAndUnwrap(Assembly.GetExecutingAsse
mbly
().FullName, typeof(TraceabilityAddIn).FullName);                       
        
// It doesn't matter whether I hard-code the assembly and type name or
not //_AddIn =
(ITraceabilityAddIn)ad.CreateInstanceAndUnwrap("Traceability.AddIn",
"Traceability.AddIn.TraceabilityAddIn");                        

}
catch(Exception e)
{
        // I get an exception--I shouldn't
        Debug.WriteLine(e.Message);
        Debug.WriteLine(e.StackTrace);
}

}
}

You can read messages from the Advanced DOTNET archive, unsubscribe from
Advanced DOTNET, or subscribe to other DevelopMentor lists at
http://discuss.develop.com.

You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to