-----------------------------------------------
AppDomainSetup appConfig =
new AppDomainSetup();appConfig.ApplicationBase = "C.\\myFolder";
AppDomain myAppDomain= AppDomain.CreateDomain("ProviderDomain", null, appConfig);
Assembly providerImplAssembly1 = Assembly.Load("assemblyName"); //success
Assembly providerImplAssembly2 = myAppDomain.Load("assemblyName"); //fail
You can use the FUSLOGVW.exe utility shipped with .NET Framework SDK to
trace the details of the failed assembly bindings. If you want to also
check the information of successful bindings, you need to set the
HKLM\Software\Microsoft\Fusion\ForceLog registry key to 1; otherwise the
FUSLOGVW will not log the successful binding info.
Regards,
Felix Wu
=============
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>From: "Alek" <amaria...@wappi.com>
>Subject: different behaviour beetween Assembly.Load() and
myAppDomain.Load()
>Date: Thu, 17 Oct 2002 19:25:54 +0200
>Lines: 115
>MIME-Version: 1.0
>Content-Type: multipart/alternative;
> boundary="----=_NextPart_000_0024_01C27613.030B8CE0"
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.2720.3000
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
>Message-ID: <uc#yHGgdCHA.1756@tkmsftngp12>
>Newsgroups: microsoft.public.dotnet.framework
>NNTP-Posting-Host: 212.7.72.134
>Path: cpmsftngxa09!cpmsftngxa08!tkmsftngp01!tkmsftngp12
>Xref: cpmsftngxa09 microsoft.public.dotnet.framework:28035
>X-Tomcat-NG: microsoft.public.dotnet.framework
AppDomain.Load() returns the assembly loaded and Assembly is marshal by
value, so remoting loads the assembly into the calling appdomain when
marshalling the result. That's to say, two instance of myAssembly.dll are
created, one is from c:\myFolder (in the new AppDomain "myAppDomain") and
the other is from C:/ClientApplicationFolder/myAssembly.dll (in the calling
domain). The FileNotFoundException occurred, because myAssembly.dll only
exists in the c:\myFolder folder.
AppDomain.Load() isn't intended for what you're doing since, even if you
could load the assembly only into the target appdomain, you couldn't do
anything useful with it. The first time you unwrap an object handle from
CreateInstance or its like, the assembly going to get loaded into the base
domain again (the returned object may be cast as Object, but the runtime
still needs to associate the real type with the instance, and that involves
loading the declaring assembly).
To achieve what you want, you need some code running in the target
appdomain that you can send commands to in order to load assemblies and run
methods. Create a small assembly exporting a marshal by ref type with
methods such as LoadAssembly() and InvokeMethod(). Then create your target
appdomain, load your hosting assembly using CreateInstanceAndUnwrap() -- at
this point your hosting assembly will also get loaded into the base domain
-- and you can proceed to make demands on the proxy returned, safely
isolated from direct contact with the target assembly.
Hope this helps.
Regards,
Felix Wu
=============
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>From: "Alek" <amaria...@wappi.com>
>References: <uc#yHGgdCHA.1756@tkmsftngp12> <TpW9wUReCHA.2764@cpmsftngxa08>
>Subject: Re: different behaviour beetween Assembly.Load() and
myAppDomain.Load()
>Date: Tue, 22 Oct 2002 17:04:35 +0200
>Lines: 385
>MIME-Version: 1.0
>Content-Type: multipart/alternative;
> boundary="----=_NextPart_000_0017_01C279ED.19260F90"
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.2720.3000
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
>Message-ID: <ewrOZudeCHA.2636@tkmsftngp08>
>Newsgroups: microsoft.public.dotnet.framework
>NNTP-Posting-Host: 212.7.72.134
>Path: cpmsftngxa06!tkmsftngp01!tkmsftngp08
>Xref: cpmsftngxa06 microsoft.public.dotnet.framework:28337
>X-Tomcat-NG: microsoft.public.dotnet.framework
Besides the method I mentioned in my last post, you can also use the
AssemblyResolve event to workaround this issue. AssemblyResolve event will
be fired when the resolution of an assembly fails. You can register a
ResolveEventHandler method with the AssemblyResolve event of your current
domain. In this ResolveEventHandler method, you can extract the assembly
file name from the ResolveEventArgs and call Assembly.LoadFrom method to
load this target assembly from a specified location. In your case, I think
you can simply return the current executing assembly. since you do not need
the myAssembly.dll assembly in your current domain.
AppDomainSetup appConfig = new AppDomainSetup();
appConfig.ApplicationBase ="c:\\myFolder";
AppDomain.CurrentDomain.AssemblyResolve+=new
ResolveEventHandler( this.MyResolveHandler);
AppDomain myAppDomain= AppDomain.CreateDomain("ProviderDomain",
null, appConfig);
Assembly providerImplAssembly2 =
myAppDomain.Load("ClassLibrary1");
private Assembly MyResolveHandler(object sender,ResolveEventArgs e)
{
return Assembly.GetExecutingAssembly();
}
I recommend you unregister the MyResolveHandler method with the
AssemblyResolve event after the call:
myAppDomain.Load("ClassLibrary1");
otherwise this method will be called everytime the current domain fails to
load assemblies.
Hope this helps.
Regards,
Felix Wu
=============
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>From: "Alek" <amaria...@wappi.com>
>References: <uc#yHGgdCHA.1756@tkmsftngp12> <TpW9wUReCHA.2764@cpmsftngxa08>
>Subject: Re: different behaviour beetween Assembly.Load() and
myAppDomain.Load()
>Date: Tue, 22 Oct 2002 17:04:35 +0200
>Lines: 385
>MIME-Version: 1.0
>Content-Type: multipart/alternative;
> boundary="----=_NextPart_000_0017_01C279ED.19260F90"
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.2720.3000
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
>Message-ID: <ewrOZudeCHA.2636@tkmsftngp08>
>Newsgroups: microsoft.public.dotnet.framework
>NNTP-Posting-Host: 212.7.72.134
>Path: cpmsftngxa06!tkmsftngp01!tkmsftngp08
>Xref: cpmsftngxa06 microsoft.public.dotnet.framework:28337
>X-Tomcat-NG: microsoft.public.dotnet.framework
>
thank you very much
Alek
What does your code look like? I'm glad to look into it if you can post it.
Also, take a look at the MarshalByRefObject Class for more information
about Inter-AppDomian communication.
If you just want to load an assembly into another domain and have it run in
that domain, I would sugget you use the AssemblyResolve event as I
mentioned in my last post. It is easy to implement and with better
efficiency.
Regards,
Felix Wu
=============
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>From: "Alek" <amaria...@wappi.com>
>References: <uc#yHGgdCHA.1756@tkmsftngp12> <TpW9wUReCHA.2764@cpmsftngxa08>
<ewrOZudeCHA.2636@tkmsftngp08> <sJLUFS2eCHA.1308@cpmsftngxa08>
>Subject: Re: different behaviour beetween Assembly.Load() and
myAppDomain.Load()
>Date: Tue, 29 Oct 2002 16:52:45 +0100
>Lines: 179
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.2720.3000
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
>Message-ID: <ulF$2J2fCHA.1104@tkmsftngp11>
>Newsgroups: microsoft.public.dotnet.framework
>NNTP-Posting-Host: 212.7.72.134
>Path: cpmsftngxa09!cpmsftngxa06!tkmsftngp01!tkmsftngp11
>Xref: cpmsftngxa09 microsoft.public.dotnet.framework:28966
>X-Tomcat-NG: microsoft.public.dotnet.framework