简体   繁体   English

从网络共享运行Winforms应用程序

[英]Running Winforms application from network share

I have a .Net application that is located on a network drive, when launching it, it immediately crashes. 我有一个位于网络驱动器上的.Net应用程序,启动它时,它立即崩溃。 Analyzed the log using WinDBG and this is the exception that caused it: 使用WinDBG分析了日志,这是引起日志的异常:

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. 我的应用程序没有定义SNK,但它使用的是具有SNK的NLog。 I also added [assembly: AllowPartiallyTrustedCallers] in NLog so my application will be able to use it. 我还在NLog中添加了[assembly:AllowPartiallyTrustedCallers],因此我的应用程序将能够使用它。 Using mscorcfg.msc, Runtime security policy, I've given NLog.dll FullTrust. 使用mscorcfg.msc(运行时安全策略),我给了NLog.dll FullTrust。 I also gave my application FullTrust, but the condition that I used was via the Publisher instead of Strong Name. 我还给了我的应用程序FullTrust,但是我使用的条件是通过发布者而不是强名称。 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. 也许这可能是问题所在,但是从我的例外出发,我相信它与MyApp.config有关。

What am I missing? 我想念什么?

Found the solution! 找到了解决方案!

Of course using SNK is great, I believe this is one way to solve the problem. 当然使用SNK很棒,我相信这是解决问题的一种方法。

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. 显然,我遇到的问题是我尝试从\\\\ 172.16.27.229而不是使用\\\\ 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. 当我将路径与\\\\ IP一起使用时,它几乎没有任何权限,但是当我使用\\\\ name时,它具有“不受限制”的权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM