C# App Runtime library path

S

sealo

Hello,
How does the C# App search the library in the runtime?
Say, I build a C# App A, which use B.dll, and B.dll use the C.dll.
I specify the B.dll and C.dll path in the IDE, and build was passed.
If I run the app, do I need to put the B.dll and C.dll in the same
directory with the App?
How does the app search the library which he need?
Or, is there some environment variable of Library Path in .NET, like
"LD_LIBRARY_PATH" in UNIX?
 
P

Peter Bradley

Someone who's read the spec will be able to give you a more detailed answer
than this, but my rule of thumb is that the .NET Framework looks first in
the GAC and then, if it can't find the assembly there, it looks in the same
directory as the calling executable. If you are using VS, the dlls will be
put in the right places for you.

So, in your example, if none of the assemblies is in the GAC, the Framework
will look for both dlls in the directory holding A.exe. The paths you
specify in the IDE are irrelevant AFAIK.

Cheers


Peter
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

sealo said:
Hello,
How does the C# App search the library in the runtime?
Say, I build a C# App A, which use B.dll, and B.dll use the C.dll.
I specify the B.dll and C.dll path in the IDE, and build was passed.
If I run the app, do I need to put the B.dll and C.dll in the same
directory with the App?

The IDE will copy the dll to the .exe's folder (unless otherwise
especified).
If you need create a setup project it will include all the needed components
to run your app.
 
N

Nicholas Paldino [.NET/C# MVP]

The process you are referring to (locating referenced assemblies) is
known as fusion in .NET. You can find more information on this process (the
general case scenario is cut and dry, but there are a lot of exceptions),
check out the section of the MSDN documentation titled "How the Runtime
Locates Assemblies", located at (make sure you check the topics under "See
Also" as well):

http://msdn2.microsoft.com/en-us/library/aa720133(VS.71).aspx

Richard Grimes also has a detailed walkthrough which can be of help as
well:

http://www.grimes.demon.co.uk/workshops/fusionWS.htm

Granted, the VS.NET IDE is going to do the work for you of placing your
referenced assemblies in the app's directory, but it doesn't hurt to know
the details.
 

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