PC Review


Reply
Thread Tools Rate Thread

Differences loading Type into AppDomain with .NET and COM Interop?

 
 
Rick Strahl [MVP]
Guest
Posts: n/a
 
      21st Jan 2005
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/
----------------------------------
Making waves on the Web



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Loading the existing AppDomain Debasish Pramanik Microsoft Dot NET Framework 1 28th Sep 2006 05:33 PM
Appdomain loading question Andrew Ducker Microsoft C# .NET 1 7th Dec 2005 05:36 PM
loading assembly new appdomain marfi95@yahoo.com Microsoft VB .NET 0 21st Mar 2005 09:35 PM
Repost: Isolation In AppDomain - How to prevent the main AppDomain to crash when another AppDomain Crashes?????? José Joye Microsoft C# .NET 7 6th Nov 2003 02:10 PM
Repost: Isolation In AppDomain - How to prevent the main AppDomain to crash when another AppDomain Crashes?????? José Joye Microsoft Dot NET 7 6th Nov 2003 02:10 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:59 PM.