Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

different behaviour beetween Assembly.Load() and myAppDomain.Load()

19 views
Skip to first unread message

Alek

unread,
Oct 17, 2002, 1:25:54 PM10/17/02
to
My application (not in same folder of assembly.dll) calls following code by COM interop.
The problem is that Assembly.Load(...)  has success, instead myAppDomain.Load(...) fails :
 
"File or assembly name CRIBIS.SkyMinder.Provider.Catalogo.CatalogoProvider, or one of its dependencies, was not found."
Why? How can load an assembly into specific AppDomain not having assembly in same folder of calling application?
 
 
code is:

-----------------------------------------------

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

-----------------------------------------------
 
 
NB If I put my application into same folder of assembly both loading have success
 
 
Thank you for help
 
Alek
 

Felix Wu [MS]

unread,
Oct 21, 2002, 11:19:53 AM10/21/02
to
Hi Alek,

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

Alek

unread,
Oct 22, 2002, 11:04:35 AM10/22/02
to
Hi Felix,
I used FUSLOGVW.exe (very useful !) and both Assembly.Load(...) and myAppDomain.Load(...) write 2 messages on  "Assembly Binding Log Viewer".
 
First message is "The operation failed...." and is identical for  Assembly.Load(...) and for myAppDomain.Load(...) 
 
Second message is "The operation was successful...." and differences are:
 
Assembly.Load(...)
LOG: Appbase = c:\ClientApplicationFolder" (folder containing .exe client)
....
Calling assembly : myAssembly
....
LOG: Attempting download of new URL file:///C:/ClientApplicationFolder/myAssembly.dll.
LOG: Attempting download of new URL file:///C:/ClientApplicationFolder/myAssembly/myAssembly.dll.
LOG: Attempting download of new URL file:///C:/ClientApplicationFolder/myAssembly.exe.
LOG: Attempting download of new URL file:///C:/ClientApplicationFolder/myAssembly/myAssembly.exe.
LOG: Attempting download of new URL file:///C:/myFolder /myAssembly.dll.
 
myAppDomain.Load(...) 
LOG: Appbase = c:\myFolder   (folder containing myAssembly.dll)
....
Calling assembly : (Unknown).
....
LOG: Attempting application configuration file download.
...
LOG: Attempting download of new URL file:///C:/myFolder /myAssembly.dll.
 
 
the problem is that myAppDomain.Load(...) throws an exception "File or assembly name myAssembly, or one of its dependencies, was not found"
Have you any idea ? Why this behaviour ?
 
 
 
I tried also not setting application base :
 
AppDomainSetup appConfig = new AppDomainSetup(); 
//appConfig.ApplicationBase = "C.\\myFolder";

AppDomain myAppDomain= AppDomain.CreateDomain("ProviderDomain", null,  appConfig);
Assembly providerImplAssembly2 = myAppDomain.Load("assemblyName"); //fail
 
In this case loading writes only 1 message on "Assembly Binding Log Viewer"  ("The operation failed....") that contains:
...
LOG: Attempting download of new URL file:///C:/ClientApplicationFolder/myAssembly.dll.
LOG: Attempting download of new URL file:///C:/ClientApplicationFolder/myAssembly/myAssembly.dll.
LOG: Attempting download of new URL file:///C:/ClientApplicationFolder/myAssembly.exe.
LOG: Attempting download of new URL file:///C:/ClientApplicationFolder/myAssembly/myAssembly.exe.
....
 
but is missing:
 
LOG: Attempting download of new URL file:///C:/myFolder /myAssembly.dll.
.
 
 
 
thank you very much
 
 
 
 
 

Felix Wu [MS]

unread,
Oct 24, 2002, 9:52:59 AM10/24/02
to
Hi Alek,

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

Felix Wu [MS]

unread,
Oct 27, 2002, 3:12:18 AM10/27/02
to
Hi Alek,

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
>

Alek

unread,
Oct 29, 2002, 10:52:45 AM10/29/02
to
Hi Felix,
may you give me a simple example?
I tried to use CreateInstanceAndUnwrap() but I had same problems .... :(

thank you very much

Alek

Felix Wu [MS]

unread,
Oct 30, 2002, 5:53:27 AM10/30/02
to
Hi 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

Alek

unread,
Nov 12, 2002, 1:53:51 PM11/12/02
to
Hi Felix,
I can't post code but I think to have find a way!
 
As you suggest me client application must load dinamically an assembly_wrap into an appdomain that I have initialized with specific ApplicationBase.
Assembly_wrap can now find and load ServerAssembly into the specific ApplicationBase.
 
The only constraint is that assembly_wrap must be in same folder of client application I think...
 
In other words I must design project as following:
 
VB6client (in folder "xx") 
    loads
        myAssembly registered with regasm /codebase (in folder "yy") 
            loads
                assembly_wrap (in folder "xx" ARGHH!!!) with AppDomain having ApplicationBase ="yy"
                    loads
                        ServerAssembly. (in folder "yy")
 
... so folder "xx" must contain only wrap and not all ServerAssembly ...
 
do you think there is a way to put assembly_wrap into folder "yy" ?
 
 
bye
Alek
 
0 new messages