0

I have a .Net application that is located on a network drive, when launching it, it immediately crashes. Analyzed the log using WinDBG and this is the exception that caused it:

Exception object: 00000000027806c8
Exception type: System.Security.SecurityException
Message: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
InnerException: <none>
StackTrace (generated):
    SP               IP               Function
    000000000018BAC0 0000000000000001 mscorlib_ni!System.Security.CodeAccessSecurityEngine.Check(System.Object, System.Threading.StackCrawlMark ByRef, Boolean)+0x2
    000000000018BAC0 000007FEDFD88CC7 mscorlib_ni!System.Security.CodeAccessPermission.Demand()+0x37
    000000000018BB00 000007FEDFD8838D mscorlib_ni!System.AppDomainSetup.VerifyDir(System.String, Boolean)+0x8d
    000000000018BB50 000007FF001C119B NLog!NLog.Config.ConfigSectionHandler.System.Configuration.IConfigurationSectionHandler.Create(System.Object, System.Object, System.Xml.XmlNode)+0x18b
    000000000018BBD0 000007FEDE78EDC2 System_Configuration_ni!System.Configuration.RuntimeConfigurationRecord+RuntimeConfigurationFactory.CreateSectionImpl(System.Configuration.RuntimeConfigurationRecord, System.Configuration.FactoryRecord, System.Configuration.SectionRecord, System.Object, System.Configuration.ConfigXmlReader)+0x162
    000000000018BC20 000007FEDE784566 System_Configuration_ni!System.Configuration.RuntimeConfigurationRecord+RuntimeConfigurationFactory.CreateSectionWithRestrictedPermissions(System.Configuration.RuntimeConfigurationRecord, System.Configuration.FactoryRecord, System.Configuration.SectionRecord, System.Object, System.Configuration.ConfigXmlReader)+0x86
    000000000018BCA0 000007FEDE78EB4E System_Configuration_ni!System.Configuration.RuntimeConfigurationRecord.CreateSection(Boolean, System.Configuration.FactoryRecord, System.Configuration.SectionRecord, System.Object, System.Configuration.ConfigXmlReader)+0x5e
    000000000018BD10 000007FEDE78EA52 System_Configuration_ni!System.Configuration.BaseConfigurationRecord.CallCreateSection(Boolean, System.Configuration.FactoryRecord, System.Configuration.SectionRecord, System.Object, System.Configuration.ConfigXmlReader, System.String, Int32)+0x92

StackTraceString: <none>
HResult: 8013150a
SecurityException Message: 
The action that failed was:
Demand
The type of the first permission that failed was:
System.Security.Permissions.FileIOPermission
The first permission that failed was:
<IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
PathDiscovery="\\172.16.27.229\Apps\MyApp.config"/>

My application doesn't have an SNK defined but it is using NLog which has an SNK. I also added [assembly: AllowPartiallyTrustedCallers] in NLog so my application will be able to use it. Using mscorcfg.msc, Runtime security policy, I've given NLog.dll FullTrust. I also gave my application FullTrust, but the condition that I used was via the Publisher instead of Strong Name. Perhaps that could be the issue, but from the that I got in the exception I believe it has something to do with the MyApp.config.

What am I missing?

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
bondar
  • 484
  • 1
  • 3
  • 16
  • The error message suggests that the machine or user account doesn't have sufficient file I/O permissions. – Robert Harvey Jan 08 '15 at 16:48
  • 1
    Related: http://stackoverflow.com/questions/423504/net-2-0-application-from-network-share-without-fulltrust – Lynn Crumbling Jan 08 '15 at 16:48
  • Does your user have read privs on the corresponding .config file? – Lynn Crumbling Jan 08 '15 at 16:51
  • 1
    This link contains a lot of information about debugging Code Access Security, http://www.emmet-gray.com/Articles/CodeAccessSecurity.html There's a lot of things that could be going wrong. – Steve Mitcham Jan 08 '15 at 16:51
  • 1
    Your app has to be signed as well, and both your key and NLog's key have to be setup following the instructions in Lynn's links. Plus any other third party keys from assemblies you are using – Steve Mitcham Jan 08 '15 at 16:54
  • Thanks for the replies! @LynnCrumbling, my user has read privileges bot for the file and the entire folder. – bondar Jan 09 '15 at 17:18
  • @SteveMitcham, my application is signed but doesn't have Strong Name, also not all of its assemblies have strong name. Is it important that ALL the assemblies share the same SNK or perhaps some of them can use different SNK? – bondar Jan 09 '15 at 17:20

1 Answers1

0

Found the solution!

Of course using SNK is great, I believe this is one way to solve the problem.

Apparently the issue that I had was with the fact that I've tried to launch the application from \\172.16.27.229 rather than using \\MyNAS. I understood it by evaluating the permissions for the given assembly. When I used the path with \\IP it barely got any permissions, but when I used the \\name it got "Unrestricted" permissions.

bondar
  • 484
  • 1
  • 3
  • 16