I have a .NET 3.5 application that consists of two assemblies:
foo.exe and bar.dll
foo.exe calls a method in bar.dll that tries to get the temp folder path using Path.GetTempPath()
If I place both the .exe and the dll in a unc folder (\\netdrive\app\), there is no problem, the Path.GetTempPath() in bar.dll works as expected.
But: If I place the exe file in \\netdrive\app\ and the dll in
\\netdrive\app\bin\ the Path.GetTempPath() throws an exception: Request for the permission of type 'System.Security.Permissions.EnvironmentPermission, mscorlib, Version=188.8.131.52, Culture=neutral, PublicKeyToken=b77a5c561934e089'
I have added probing for /bin in the app.config.
Why does bar.dll get lower permissions when it is placed in the \bin subfolder? And how can I correct this?
You may put following code in both the exe assembly and the dll assembly, to print the security zone they belong to:
Evidence evi = Assembly.GetExecutingAssembly().Evidence;
IEnumerator e = evi.GetEnumerator();
Zone zone = e.Current as Zone;
if (zone != null)
My test result shows that:
1. If the exe and dll locate in same folder, both of them output "MyComputer" which refers to "My_Computer_Zone".
2. If the dll is putted in the bin folder, the exe output "MyComputer", but the dll shows "Intranet" (which means "LocalIntranet_Zone".
I haven't find out why, but, to fixed this issue, you may grant
Unrestricted permission of System.Security.Permissions.EnvironmentPermission to LocalInternet_Zone; or, create a sub-group under LocalInternet_Zone, give
file://netdrive/app/bin/mylib.dll a FullTrust permission set.