PC Review


Reply
Thread Tools Rate Thread

Best way to consume an assembly loaded at runtime in separate AppDomain

 
 
Ashutosh
Guest
Posts: n/a
 
      23rd Oct 2008
Hi,
Have few doubts in using an assembly in different appdomain.

Besides reflection what are the other way to consume a type in a
assembly which is loaded at runtime using AppDomain.Load or
Assembly.Load[From] ?

What about marshaling the data between app domain?? Should the type in
the assembly inherit from MarshalByRefObject class?

Lastly, why can't I use an interface to assess the object of the class
thats loaded like this

AppDomain d = AppDomain.CreateDomain("ashuu");
Assembly a = d.Load("ClassLibrary1, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=c4510fb7f9c15154");
object o = a.CreateInstance("ClassLibrary1.TestClass123");
ISayHello h = o as ISayHello;
if (h != null) //<--------- h is always null
h.Hello();


The class ClassLibrary1.TestClass123 implements the interface ISayHello,
but the object h (shown above) is always null.

Can someone please clarify?

Thanks & Regards,
Ashutosh
 
Reply With Quote
 
 
 
 
Ashutosh
Guest
Posts: n/a
 
      23rd Oct 2008
Also, I am looking out for ways other than .Net Remoting.

Thanks & Regards,
Ashutosh

Ashutosh wrote:
> Hi,
> Have few doubts in using an assembly in different appdomain.
>
> Besides reflection what are the other way to consume a type in a
> assembly which is loaded at runtime using AppDomain.Load or
> Assembly.Load[From] ?
>
> What about marshaling the data between app domain?? Should the type in
> the assembly inherit from MarshalByRefObject class?
>
> Lastly, why can't I use an interface to assess the object of the class
> thats loaded like this
>
> AppDomain d = AppDomain.CreateDomain("ashuu");
> Assembly a = d.Load("ClassLibrary1, Version=1.0.0.0,
> Culture=neutral, PublicKeyToken=c4510fb7f9c15154");
> object o = a.CreateInstance("ClassLibrary1.TestClass123");
> ISayHello h = o as ISayHello;
> if (h != null) //<--------- h is always null
> h.Hello();
>
>
> The class ClassLibrary1.TestClass123 implements the interface
> ISayHello, but the object h (shown above) is always null.
>
> Can someone please clarify?
>
> Thanks & Regards,
> Ashutosh

 
Reply With Quote
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      24th Oct 2008
Hi Ashutosh ,

AppDomain is a sandbox unit for .Net code; it acts a bit like the Process
in the OS. The official recommended approach to communicate between
AppDomains is using .Net remoting. Since your assembly and types are loaded
into the remote domain, you can not use it directly in the default domain.

You'd better leverage an add-in manager class deriving from
MarshalByRefObject so that it can take advantage of remoting to communicate
between the host AppDomain and the sandboxed domain. The article below
talks about the details and contains the sample code:
"Discover Techniques for Safely Hosting Untrusted Add-Ins with the .NET
Framework 2.0"
http://msdn.microsoft.com/en-us/magazine/cc163701.aspx

Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=========================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(E-Mail Removed).

This posting is provided "AS IS" with no warranties, and confers no rights.

 
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
Problem with assembly loaded at runtime Luis Arvayo Microsoft C# .NET 5 21st Jan 2006 02:16 AM
how to load a C# dll from another C# assembly if the path of the loaded dll is not known until runtime Daniel Microsoft Dot NET 1 30th Nov 2004 03:59 PM
how to load a C# dll from another C# assembly if the path of the loaded dll is not known until runtime Daniel Microsoft Dot NET Framework 2 30th Nov 2004 08:49 AM
how to load a C# dll from another C# assembly if the path of the loaded dll is not known until runtime Daniel Microsoft C# .NET 1 30th Nov 2004 06:13 AM
Assembly.Load unload separate AppDomain problem Lauren Hines Microsoft C# .NET 2 24th May 2004 06:22 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:26 AM.