R
Rick Strahl [MVP]
Hi all,
I'm trying to create COM wrapper around a class that needs to use remoting
to perform its tasks, so that I can unload the AppDomain after it's done
with
it's work.
I've build the code to create the AppDomain and load the MarshalByRef object
into the other domain. All works well when running this code in .NET through
a WinForm where I get the Remote Proxy and can fire away at the methods.
However, if I run the exact same code through COM the Remoting through the
AppDomain fails. Specifically it looks like the Proxy is created but it
cannot be cast to the proper type.
public TypeParser CreateTypeParser()
{
if (!this.CreateAppDomain(null))
return null;
object T = this.LocalAppDomain.CreateInstance( "wwReflection",
"Westwind.wwReflection.TypeParser" ).Unwrap();
/// *** Ok both in COM and WinForm - returns MarshalByRef object
System.Windows.Forms.MessageBox.Show( T.GetType().Name +
"\r\n" + T.ToString() );
// *** this works in WinForm but not in COM. COM get null
TypeParser Parser = T as Westwind.wwReflection.TypeParser;
// Always get a result in WinFOrm
return Parser;
}
[ClassInterface(ClassInterfaceType.AutoDual)]
[ProgId("wwReflection.TypeParser")]
public class TypeParser : MarshalByRefObject
{
....
}
I've stepped through this code when running under COM and the reference
comes back from CreateInstance() but it is typed differently than when
it runs under .NET. The MessageBox call returns MarshalByRefObj and
TypeParser,
where under WinForms I get TypeParser in both instances.
Just for kicks I tried to get at the object with Reflection and that too
didn't
work. The TypeParser class exists in the same project, so there should be no
type identification problems.
If I mistype the type name it fails with an exception so the CreateInstance
call appears to be working.
Any ideas on why this works in WinForms and not via COM invokation?
+++ Rick ---
--
Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
http://www.west-wind.com/wwThreads/
I'm trying to create COM wrapper around a class that needs to use remoting
to perform its tasks, so that I can unload the AppDomain after it's done
with
it's work.
I've build the code to create the AppDomain and load the MarshalByRef object
into the other domain. All works well when running this code in .NET through
a WinForm where I get the Remote Proxy and can fire away at the methods.
However, if I run the exact same code through COM the Remoting through the
AppDomain fails. Specifically it looks like the Proxy is created but it
cannot be cast to the proper type.
public TypeParser CreateTypeParser()
{
if (!this.CreateAppDomain(null))
return null;
object T = this.LocalAppDomain.CreateInstance( "wwReflection",
"Westwind.wwReflection.TypeParser" ).Unwrap();
/// *** Ok both in COM and WinForm - returns MarshalByRef object
System.Windows.Forms.MessageBox.Show( T.GetType().Name +
"\r\n" + T.ToString() );
// *** this works in WinForm but not in COM. COM get null
TypeParser Parser = T as Westwind.wwReflection.TypeParser;
// Always get a result in WinFOrm
return Parser;
}
[ClassInterface(ClassInterfaceType.AutoDual)]
[ProgId("wwReflection.TypeParser")]
public class TypeParser : MarshalByRefObject
{
....
}
I've stepped through this code when running under COM and the reference
comes back from CreateInstance() but it is typed differently than when
it runs under .NET. The MessageBox call returns MarshalByRefObj and
TypeParser,
where under WinForms I get TypeParser in both instances.
Just for kicks I tried to get at the object with Reflection and that too
didn't
work. The TypeParser class exists in the same project, so there should be no
type identification problems.
If I mistype the type name it fails with an exception so the CreateInstance
call appears to be working.
Any ideas on why this works in WinForms and not via COM invokation?
+++ Rick ---
--
Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
http://www.west-wind.com/wwThreads/