Difference of AppDomain.CurrentDomain.BaseDirectory and Environment.CurrentDirectory

C

cok119

Hi, all

What is the difference of the follows ?

1. AppDomain.CurrentDomain.BaseDirectory
2. Environment.CurrentDirectory
3. AppDomainSetup.ApplicationBase

When I do Assembly.Load(...)
Which is used ?

thanks
 
M

Mattias Sjögren

What is the difference of the follows ?
1. AppDomain.CurrentDomain.BaseDirectory
2. Environment.CurrentDirectory
3. AppDomainSetup.ApplicationBase

1 and 3 are basically thr same. The difference is that
AppDomainSetup.ApplicationBase is writable, but
AppDomain.BaseDirectory is read-only since you can't change it after
the appdomain has been created.

2 is something entirely different. It's used to resolve relative
paths, among other things. You can change the CurrentDirectory at any
time in your code, and it may also be changed by things like the
FileDialogs.

When I do Assembly.Load(...)
Which is used ?

See http://msdn2.microsoft.com/en-us/library/yx7xezcf.aspx


Mattias
 
C

cok119

Hi, Mattias

thank you for your reply.

after read MSDN ,I make a test

Make Environment.CurrentDirectory different from
AppDomain.CurrentDomain.BaseDirectory
when I move Plugin.dll into CurrentDirectory , and
Assembly.Load("Plugin.dll ") work fine.
but when I move Plugin.dll into BaseDirectory, Assembly.Load("Plugin.dll ")
dosen't work.

It seem's that Assembly.Load search CurrentDirectory , and NOT search
BaseDirectory

Is it right ?
 
M

Mattias Sjögren

Make Environment.CurrentDirectory different from
AppDomain.CurrentDomain.BaseDirectory
when I move Plugin.dll into CurrentDirectory , and
Assembly.Load("Plugin.dll ") work fine.
but when I move Plugin.dll into BaseDirectory, Assembly.Load("Plugin.dll ")
dosen't work.

It seem's that Assembly.Load search CurrentDirectory , and NOT search
BaseDirectory

Is it right ?


Assembly.Load takes an assembly name (e.g. "Plugin"), not a file name
(like "Plugin.dll"). So I'm guessing you're actually using
Assembly.LoadFrom. I assume LoadFrom uses the CurrentDirectory to
resolve relative paths. If you instead use Assembly.Load("Plugin") I
think it should look in the appbase directory.


Mattias
 
N

Nie longhai

Hi, Mattias

It's my mistake!

I use FileMon find :

Assembly.Load("Test") search follow path

BaseDirectory\\Test.dll
BaseDirectory\\Test\\Test.dll
BaseDirectory\\Test.exe
BaseDirectory\\Test\\Test.dll

but

CompilerParameters.ReferencedAssemblies.Add("Test.dll") search follow path

CurrentDirectory\\Test.dll

thank you very much! :p
 

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