Home All Groups Group Topic Archive Search About

Difference of AppDomain.CurrentDomain.BaseDirectory and Environment.CurrentDirectory

Author
15 Oct 2006 2:09 PM
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

Author
15 Oct 2006 2:30 PM
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

--
Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Author
15 Oct 2006 3:23 PM
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 ?

"Mattias Sj?gren" <mattias.dont.want.spam@mvps.org>
??????:%23wKzfZG8GHA.4***@TK2MSFTNGP05.phx.gbl...
Show quote
> >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
>
> --
> Mattias Sjögren [C# MVP]  mattias @ mvps.org
> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
> Please reply only to the newsgroup.
Author
15 Oct 2006 9:19 PM
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

--
Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Author
16 Oct 2006 1:10 AM
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

"Mattias Sj?gren" <mattias.dont.want.spam@mvps.org>
??????:O7JrM%23J8GHA.***@TK2MSFTNGP03.phx.gbl...
Show quote
> >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
>
> --
> Mattias Sjögren [C# MVP]  mattias @ mvps.org
> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
> Please reply only to the newsgroup.

AddThis Social Bookmark Button