Difference of AppDomain.CurrentDomain.BaseDirectory and Environment.CurrentDirectory

  • Thread starter Thread starter cok119
  • Start date Start date
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
 
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
 
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 ?
 
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
 
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
 
Back
Top