473,387 Members | 1,502 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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
Oct 23 '08 #1
2 1247
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
Oct 23 '08 #2
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:
ms****@microsoft.com.

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

Oct 24 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Daylor | last post by:
can shadowcopy be done with private assembly ? any info about how shadowcopy actually works ? when im compiling an assembly (while the assembly file is in use ), what i need to do ? change...
1
by: Serge calderara | last post by:
Dear all, Is there a way to get the list of references attached to my application by code? The idea is that when my application start, I would like to log in a file the version of all...
0
by: Derek Young | last post by:
I have a unit test I've written that tests a lot of managed C++/unmanaged C++/C# interactions. I'm running it under NUnit which creates a separate AppDomain for the test, runs it, then unloads the...
1
by: Luis Pinho | last post by:
Hi There, I've got a server that is waiting for requests, these request correspond to calls to objects that are specified in assemblies stored in the GAC. To do this, I use reflection to call...
4
by: Barry Kelly | last post by:
I'm designing an application framework which will, amongst other things, live in an assembly hosted in the ASP.NET worker process, servicing webservice requests. Here's the scenario: APPFX is...
2
by: Dominique Vandensteen | last post by:
I want to make a program that checks for updates at start... The way I am doing this is to create 2 projects... A simple exe checks the server for the version and downloads a dll if needed. The...
6
by: Steve | last post by:
I'm playing with late binding and trying a very simple test to load an assembly In my "Host" application I have this code: <code> string modulePath =...
4
by: =?Utf-8?B?SmFu?= | last post by:
I have a .NET 2.0 application divided in two assemblies; the exe and a dll. The application generates a plugin-dll which is then loaded in a separate AppDomain (along with a second instance of my...
7
by: chage | last post by:
Hi, I have been searching around to try adding reference assembly to another assembly during runtime, programatically. Is this possible in .Net? The reason for this is because i am having...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.