Running Winforms application from network share

683 Views Asked by At

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?

1

There are 1 best solutions below

0
On BEST ANSWER

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.