Loading private assemblies from a subdirectory

R

Ratul

Hi all!

I'm writing a winforms test harness which lets me specify a subfolder
from which to load a particular .net assembly dll. The idea is that
there will be multiple subfolders, each having this dll.

To ensure that there are no conflicts with similarly named assembly dll
files, I'm am trying to load a subdirectory's dll into its own
AppDomain. However when I call the
AppDomain.CreateInstanceFromAndUnwrap method, it throws an exception,
saying "File or assembly name ImportController.dll, or one of its
dependencies, was not found"

Let me be more specific by giving you some code-snippets....

****************************

/*
This is where I'm trying to create a new AppDomain. 'subfolder' is a
subfolder name (not full path) of the directory where the test harness
exe resides. exePath is the directory of the test harness exe.
ImportController.dll is the .NET assembly dll which I know resides in
the subfolder
Client.ImportController.ImportControl is a type defined in that
assembly
The subfolder not only contains ImportController.dll, but also the
other dlls it references
*/
AppDomainSetup setup = new AppDomainSetup();
string exePath =
Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
setup.ApplicationBase = exePath;
setup.PrivateBinPath = subfolder;
AppDomain appDomain = AppDomain.CreateDomain(subfolder, null, setup);
object ic =
appDomain.CreateInstanceFromAndUnwrap("ImportController.dll",
"Client.ImportController.ImportControl");

****************************

When I run this up, I get an exception...its message being "File or
assembly name ImportController.dll, or one of its dependencies, was not
found."

This is what I see in the Assembly Binder Log Entry

****************************

*** Assembly Binder Log Entry (4/7/2006 @ 7:08:43 PM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file
specified.

Assembly manager loaded from:
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\fusion.dll
Running under executable
D:\Project\Client\Import\TestHarness\bin\Debug\TestHarness.exe
--- A detailed error log follows.

=== Pre-bind state information ===
LOG: Where-ref bind. Location =
D:\Project\Client\Import\TestHarness\bin\Debug\ImportController.dll
LOG: Appbase = D:\Project\Client\Import\TestHarness\bin\Debug
LOG: Initial PrivatePath = Current
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = NULL
Calling assembly : (Unknown).
===

LOG: Processing DEVPATH.
LOG: Attempting application configuration file download.
LOG: Download of application configuration file was attempted from
file:///D:/Project/Client/Import/TestHarness/bin/Debug/TestHarness.exe.config.
LOG: Application configuration file does not exist.
LOG: Policy not being applied to reference at this time (private,
custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL
file:///D:/Project/ClientImport/TestHarness/bin/Debug/ImportController.dll.
LOG: All probing URLs attempted and failed.

****************************

It seems to show that the PrivatePath is set to 'Current' which is the
correct subfolder name, yet it does not try to download the dll from
that location.


I'm probably being a complete dunce, or just haven't properly
understood how AppDomains work, but if you could shed some light on
this situation of mine I would really really appreciate it.

Many thanks in advance....

Ratul
 

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

Top