By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,231 Members | 1,622 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,231 IT Pros & Developers. It's quick & easy.

Help, .NET dll deployment path location

P: n/a
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
Jul 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Have you tried Assembly.GetExecutingAssembly().CodeBase?

--
____________________
Klaus H. Probst, MVP
http://www.vbbox.com/

"Vincenzo Davi" <da***@hotmail.com> wrote in message
news:7d**************************@posting.google.c om...
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

Jul 21 '05 #2

P: n/a
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

-----Original Message-----
I have created a dll with several classes in C#. One of the classesreferences 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 thefollowing code to make use of that directory:
Environment.CurrentDirectory

When I reference the dll from the new Windows Application and run, Iget an error saying the images can't be found because it's trying tofind 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'sresident directory, not the calling application?

Thanks for any help!
-Vinny Davi
.

Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.