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 / CLR / January 2006

Tip: Looking for answers? Try searching our database.

Execute an instance of a class in a new app domain

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Web Developer - 24 Jan 2006 18:40 GMT
I'm trying to create an instance of a class in a new app domain within my
process (code is below), but it always ends up executing in my original app
domain.

Here's the code to instantiate the class "Service1" in a new app domain:
Dim AD1 As AppDomain = AppDomain.CreateDomain("Service1Domain")
Dim obj As Object =
AD1.CreateInstanceFromAndUnwrap(System.IO.Directory.GetCurrentDirectory &
"\Service1.dll", "Service1.Service1")
obj.GetType().InvokeMember("Initialize", BindingFlags.InvokeMethod, Nothing,
obj, Nothing)

Here's the code for the "Service1" class:
Public Class Service1
   Inherits MarshalByRefObject
   Shared Sub Initialize()
       Console.WriteLine("Service1 initialized.")
       Console.WriteLine("Service1 App Domain: " &
AppDomain.CurrentDomain.FriendlyName)
       Console.WriteLine("Service1 Executing Thread: " &
AppDomain.CurrentDomain.GetCurrentThreadId)
   End Sub
End Class

However, I end up executing in the new app domain if I use the
ExecuteAssembly method instead:

AD1.ExecuteAssembly(System.IO.Directory.GetCurrentDirectory &
"\TestExecutable.exe")

Any ideas of what I'm doing wrong?

Thanks!
Web Developer - 24 Jan 2006 22:10 GMT
I figured this out.  I needed to provide binding flags on the CreateInstance
call:

Dim flags As BindingFlags = BindingFlags.Public Or BindingFlags.Instance Or
BindingFlags.CreateInstance

> I'm trying to create an instance of a class in a new app domain within my
> process (code is below), but it always ends up executing in my original app
[quoted text clipped - 29 lines]
>
> Thanks!

Rate this thread:







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.