Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / January 2005

Tip: Looking for answers? Try searching our database.

COM Interop and Remoting

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rick Strahl [MVP] - 16 Jan 2005 05:30 GMT
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.

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.

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;

if (Parser == null)
{
/// this code always fires with COM
 System.Windows.Forms.MessageBox.Show( "Parser is null" );
 return new TypeParser();
}

// Always get a result in WinFOrm
return Parser;

 return new TypeParser();
}

[ClassInterface(ClassInterfaceType.AutoDual)]
[ProgId("wwReflection.TypeParser")]
public class TypeParser : MarshalByRefObject
{
...
}

Using the TypeParser object directly through COM works fine - it appears
something in the Remoting system is behaving very differently in COM hosting
than in WinForm hosting. Note that there is no error for the call to
CreateInstance() as there would be if the type can't found or instantiated.
If I mistype the type name it fails with an exception.

Any ideas on what's different?

+++ Rick ---

Signature

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

Rick Strahl [MVP] - 26 Jan 2005 11:54 GMT
It turns out the problem is not due to COM interop but rather a problem in
Assembly loading. Interestingly enough the errors reflect nothing about the
fact that the assembly couldn't found or loaded correctly.

The exact problem is that CreateInstance in a new AppDomain is not
respecting the new AppDomains AppBasePath, but using the parents AppDomain
settings instead. The result was that the Assembly wanted to load out of
some odd directory.

There's more info on this here:
http://west-wind.com/weblog/posts/1358.aspx

+++ Rick ---

Signature

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

> Hi all,
>
[quoted text clipped - 14 lines]
>
>  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" +
[quoted text clipped - 32 lines]
>
> +++ Rick ---

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.