Quantcast
Channel: Common Language Runtime Internals and Architecture forum
Viewing all articles
Browse latest Browse all 1710

Local assemblies loaded via Assembly.LoadFrom are untrusted from appications launched via a symlink on Win8

$
0
0

I have an simple (console) app that uses Assembly.LoadFrom to load an assembly from the local file system (it can even be in the bin folder of the executing app).  App works fine if I run the app normally, e.g. (cd c:\users\me\Visual Studio 2012\Projects\theapp\bin\debug; theapp.exe)

If however, I create a symlink to the folder that contains the executable (e.g. mklink /d theapp c:\users\me\Visual Studio 2012\Projects\theapp\bin\debug) and then try to navigate to the symlinked directory and run the app (e.g. cd c:\theapp; theapp.exe), .Net treats the assembly as if its coming from an untrusted location. Specifically, with the default config I get the .NET 4.0 sandboxing exception (below).  If I add the "loadFromRemoteSources" flag, the assembly loads, but inspecting its evidence shows .Net believes its from the "untrusted" zone.

Note, this only happens on my Windows 8 machine.  I have the identical setup on Windows 7 and it was never an issue.

Is this a bug in Windows 8? .NET 4.0? Some strange default security configuration of Win 8?

details below.

Thanks!

c:\Users\me\Local Documents\Visual Studio 2012\Projects\ConsoleApplication1\bin\Debug>ConsoleApplication1.exe
<System.Security.Policy.Url version="1">
<Url>file:///c:/Users/me/Local Documents/Visual Studio 2012/Projects/ConsoleApplication1/bin/Debug/Test.DLL</Url>
</System.Security.Policy.Url>

<System.Security.Policy.Zone version="1">
<Zone>MyComputer</Zone>
</System.Security.Policy.Zone>

ConsoleApplication1.Test


c:\Users\me\Local Documents\Visual Studio 2012\Projects\ConsoleApplication1\bin\Debug>cd c:\

c:\>mklink /d theapp "c:\Users\me\Local Documents\Visual Studio 2012\Projects\ConsoleApplication1\bin\Debug"
symbolic link created for theapp <<===>> c:\Users\me\Local Documents\Visual Studio 2012\Projects\ConsoleApplication1\bin\Debug

c:\>cd theapp

c:\theapp>ConsoleApplication1.exe

Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'file:///c:\theapp\Test.dll' or one of its dependencies. Operation is not supported. (Ex
ception from HRESULT: 0x80131515) ---> System.NotSupportedException: An attempt was made to load an assembly from a network location which would have caused the assembly
to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If th
is load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. Seehttp://go.microsoft.com/fwlink/?LinkId=155569 for more information.
   --- End of inner exception stack trace ---
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark,
 IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark,
IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMa
rk, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean fo
rIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
   at System.Reflection.Assembly.LoadFrom(String assemblyFile)
   at ConsoleApplication1.Program.Main(String[] args) in c:\Users\me\Local Documents\Visual Studio 2012\Projects\ConsoleApplication1\Program.cs:line 24


c:\theapp>notepad ConsoleApplication1.exe.config

// adding <runtime><loadFromRemoteSource enabled="true"/></runtime>

c:\theapp>ConsoleApplication1.exe
<System.Security.Policy.Url version="1">
<Url>file:///c:/theapp/Test.DLL</Url>
</System.Security.Policy.Url>

<System.Security.Policy.Zone version="1">
<Zone>Untrusted</Zone>
</System.Security.Policy.Zone>

ConsoleApplication1.Test


c:\theapp>


Viewing all articles
Browse latest Browse all 1710

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>