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

A

Ashutosh

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
 
A

Ashutosh

Also, I am looking out for ways other than .Net Remoting.

Thanks & Regards,
Ashutosh
 
J

Jeffrey Tan[MSFT]

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 address removed).

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top