application domain

T

Tony Johansson

Hello!

If I have an exe file that is using an assembly dll and this exe file is to
be run in an application domain do I then have to load this dll into this
application domain ?

I mean if the exe file and the dll is located in the same folder will the
exe file automatically use this dll which mean that I don't have to load the
dll explicitly into the application domian.

//Tony
 
A

Arne Vajhøj

If I have an exe file that is using an assembly dll and this exe file is to
be run in an application domain do I then have to load this dll into this
application domain ?

I mean if the exe file and the dll is located in the same folder will the
exe file automatically use this dll which mean that I don't have to load the
dll explicitly into the application domian.

If you don't do anything special, then everything ends up in the
same app domain.

In general app domains (besides the default) is not something you use
that often.

Arne
 
T

Tony Johansson

Arne Vajhøj said:
If you don't do anything special, then everything ends up in the
same app domain.

In general app domains (besides the default) is not something you use that
often.

Arne

Hello!

I have done the following. I have created an exe file that is using an
assembly dll to just write something to the console.
the assembly dll have this code "Console.WriteLine("Running c-tor in
ClassLibrary1");"
I have a reference to this assembly dll in the project. I call this exe file
that should echo something to the consolse for Test.exe and the assembly dll
is called testdll.dll.

Now I have another exe file that have this code
static void Main(string[] args)
{
AppDomain d = AppDomain.CreateDomain("newDomain");
d.ExecuteAssembly("Test.exe");
}

This works good the assembly dll(testdll.dll) is automatically called when
Test.exe is called.
So my question remain when do I have to use AppDomail.Load. The docs says
Loads an Assembly into this application domain.

I can't see any point why this AppDomain.Load exist because you can use this
command
d.ExecuteAssembly("Test.exe");
to have Test.exe execute without having to use any kind of load command even
if this Test.exe is using other assembly dll
this will automatically be called just as my example show.

//Tony.
 
A

Arne Vajhøj

Arne Vajhøj said:
If you don't do anything special, then everything ends up in the
same app domain.

In general app domains (besides the default) is not something you use that
often.

Arne

Hello!

I have done the following. I have created an exe file that is using an
assembly dll to just write something to the console.
the assembly dll have this code "Console.WriteLine("Running c-tor in
ClassLibrary1");"
I have a reference to this assembly dll in the project. I call this exe file
that should echo something to the consolse for Test.exe and the assembly dll
is called testdll.dll.

Now I have another exe file that have this code
static void Main(string[] args)
{
AppDomain d = AppDomain.CreateDomain("newDomain");
d.ExecuteAssembly("Test.exe");
}

This works good the assembly dll(testdll.dll) is automatically called when
Test.exe is called.
So my question remain when do I have to use AppDomail.Load. The docs says
Loads an Assembly into this application domain.

I can't see any point why this AppDomain.Load exist because you can use this
command
d.ExecuteAssembly("Test.exe");
to have Test.exe execute without having to use any kind of load command even
if this Test.exe is using other assembly dll
this will automatically be called just as my example show.

ExecuteAssembly fundamentally loads an EXE and execute its Main.

Load fundamentally loads a DLL and return an Assembly instance
on which you can call CreateInstance to get an instance of
some class and then you can call methods on that (the easiest
is if the class implements a known interface).

The second is a lot more useful than the first!

Arne
 
T

Tony Johansson

Arne Vajhøj said:
Arne Vajhøj said:
On 22-07-2010 12:58, Tony Johansson wrote:
If I have an exe file that is using an assembly dll and this exe file
is
to
be run in an application domain do I then have to load this dll into
this
application domain ?

I mean if the exe file and the dll is located in the same folder will
the
exe file automatically use this dll which mean that I don't have to
load
the
dll explicitly into the application domian.

If you don't do anything special, then everything ends up in the
same app domain.

In general app domains (besides the default) is not something you use
that
often.

Arne

Hello!

I have done the following. I have created an exe file that is using an
assembly dll to just write something to the console.
the assembly dll have this code "Console.WriteLine("Running c-tor in
ClassLibrary1");"
I have a reference to this assembly dll in the project. I call this exe
file
that should echo something to the consolse for Test.exe and the assembly
dll
is called testdll.dll.

Now I have another exe file that have this code
static void Main(string[] args)
{
AppDomain d = AppDomain.CreateDomain("newDomain");
d.ExecuteAssembly("Test.exe");
}

This works good the assembly dll(testdll.dll) is automatically called
when
Test.exe is called.
So my question remain when do I have to use AppDomail.Load. The docs says
Loads an Assembly into this application domain.

I can't see any point why this AppDomain.Load exist because you can use
this
command
d.ExecuteAssembly("Test.exe");
to have Test.exe execute without having to use any kind of load command
even
if this Test.exe is using other assembly dll
this will automatically be called just as my example show.

ExecuteAssembly fundamentally loads an EXE and execute its Main.

Load fundamentally loads a DLL and return an Assembly instance
on which you can call CreateInstance to get an instance of
some class and then you can call methods on that (the easiest
is if the class implements a known interface).

The second is a lot more useful than the first!

Arne

Hello!

I just wonder if it's any point to have code like this when you don't use
the return value from the load method.
Here you load all the assembly that end with dll from a specific folder.
AppDomain domain = AppDomain.CreateDomain ("MyDomain");
foreach (string assembly in Directory.GetFiles (@"C:\My Assemblies",
"*.dll"))
domain.Load (assembly);

//Tony
 
A

Arne Vajhøj

Arne Vajhøj said:
"Arne Vajhøj"<[email protected]> skrev i meddelandet
On 22-07-2010 12:58, Tony Johansson wrote:
If I have an exe file that is using an assembly dll and this exe file
is
to
be run in an application domain do I then have to load this dll into
this
application domain ?

I mean if the exe file and the dll is located in the same folder will
the
exe file automatically use this dll which mean that I don't have to
load
the
dll explicitly into the application domian.

If you don't do anything special, then everything ends up in the
same app domain.

In general app domains (besides the default) is not something you use
that
often.

Arne


Hello!

I have done the following. I have created an exe file that is using an
assembly dll to just write something to the console.
the assembly dll have this code "Console.WriteLine("Running c-tor in
ClassLibrary1");"
I have a reference to this assembly dll in the project. I call this exe
file
that should echo something to the consolse for Test.exe and the assembly
dll
is called testdll.dll.

Now I have another exe file that have this code
static void Main(string[] args)
{
AppDomain d = AppDomain.CreateDomain("newDomain");
d.ExecuteAssembly("Test.exe");
}

This works good the assembly dll(testdll.dll) is automatically called
when
Test.exe is called.
So my question remain when do I have to use AppDomail.Load. The docs says
Loads an Assembly into this application domain.

I can't see any point why this AppDomain.Load exist because you can use
this
command
d.ExecuteAssembly("Test.exe");
to have Test.exe execute without having to use any kind of load command
even
if this Test.exe is using other assembly dll
this will automatically be called just as my example show.

ExecuteAssembly fundamentally loads an EXE and execute its Main.

Load fundamentally loads a DLL and return an Assembly instance
on which you can call CreateInstance to get an instance of
some class and then you can call methods on that (the easiest
is if the class implements a known interface).

The second is a lot more useful than the first!
I just wonder if it's any point to have code like this when you don't use
the return value from the load method.
Here you load all the assembly that end with dll from a specific folder.
AppDomain domain = AppDomain.CreateDomain ("MyDomain");
foreach (string assembly in Directory.GetFiles (@"C:\My Assemblies",
"*.dll"))
domain.Load (assembly);

This code does not save a reference to the loaded assemblies.

So you can not use the Assembly CreateInstance (when used with
AppDomain then CreateInstanceAndUnwrap may be more convenient).

But maybe Activator CreateInstance can still be used with those. I
don't know. I would save the assembly references and use those.

Arne
 

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

Similar Threads

more about MSIL code 2
Naming the log4net.config file? 1
assembly and reuse 7
How do debugg a .net dll 2
ngen 12
More about application domain 1
DLL versioning 1
GAC 9

Top