0

我有一个位于网络驱动器上的 .Net 应用程序,当启动它时,它会立即崩溃。使用 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"/>

我的应用程序没有定义 SNK,但它使用的是具有 SNK 的 NLog。我还在 NLog 中添加了 [assembly: AllowPartiallyTrustedCallers],以便我的应用程序能够使用它。使用运行时安全策略 mscorcfg.msc,我给了 NLog.dll FullTrust。我也给了我的应用程序 FullTrust,但我使用的条件是通过发布者而不是强名称。也许这可能是问题所在,但从我得到的异常来看,我相信它与 MyApp.config 有关。

我错过了什么?

4

1 回答 1

0

找到了解决方案!

当然使用 SNK 很好,我相信这是解决问题的一种方法。

显然,我遇到的问题是我尝试从 \\172.16.27.229 启动应用程序,而不是使用 \\MyNAS。我通过评估给定程序集的权限来理解它。当我使用带有 \\IP 的路径时,它几乎没有任何权限,但是当我使用 \\name 时,它​​获得了“无限制”权限。

于 2015-01-11T16:13:43.447 回答