Help, .NET dll deployment path location

V

Vincenzo Davi

I have created a dll with several classes in C#. One of the classes
references image files in the subdirectories of the bin/Release folder
(basically where the dll resides).

Now, I want to use the dll from a C# Windows application.

In the class that references the images in the subdirectory, I use the
following code to make use of that directory:
Environment.CurrentDirectory

When I reference the dll from the new Windows Application and run, I
get an error saying the images can't be found because it's trying to
find them in that Windows application /bin/Release.

So for example, my dll is:
C:\MyDLLApp\bin\Release\mydll.dll

My Windows app is
C:\MyWinApp\bin\Release\myWinApp.exe

What do I have to do in the dll project to make it reference the dll's
resident directory, not the calling application?

Thanks for any help!
-Vinny Davi
 
R

rs_tiin

Hi

The .Net runtime looks for specific folders when it loads
the referenced assemblies. So even if you get thecurrent
directory's path it wont be of any help as the runtime
will NOT search there. The runtime searches the AppBase,
GAC, Location in CodeBase element of config file, Location
in PrivateBinPath element of config file when a assembly
is to be loaded

You have 4 options

1) Put the referenced dll in the same location(AppBase) as
the calling assembly i.e. the bin folder. This probably
you dont want as per ur reqmt.

2) Create a subfolder inside bin and place the referenced
assembly dll there. In this case you have to add a
PrivateBinPath element in the application/web config file
with the subfolder location specified

3) If you want to place the referenced assembly dll
outside the calling application folder structure then you
have 2 options a) Using Shared Assemblies (or) b)Using the
Codebase Element

Note : Both the below options require u to strongname the
assembly

a) Shared Assemblies : Shared assemblies are those
assemblies wghich are placed in the GAC and shared across
many apps in the machine. So you can strongname your
referenced assembly and place it in the GAC using the
GACUtil utility

b) Codebase Element. What you can do in this is that,
first strongname your referenced assembly and place it in
any location on the local disk(could even be a remote
file/http server with proper permission sets). Then
specify the location in the codebase element of the config
file. This will be used by the runtime to locate your
assembly.

Also if you do not want any of this you can use the Load
Assembly function of the AppDomain to load an assembly
from any location, but i suggest you do not use this to
avoid versioning problems!!!


For more info on the above options, check out MSDN for
Shared Assemblies, CodeBase, Private BinPath,
LoadAssembly. Do post/mail me in case you have any more
doubts

hth

regards,

sr
 

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