“重写成员时违反了继承安全规则”与 EntLib 5.0 和 .NET 4

发布于 2024-10-17 05:24:36 字数 3200 浏览 4 评论 0原文

我正在使用 EntLib 5.0 和 .NET 4。它可以正常工作,但现在我使用了 ILMerge 以便将所有 dll 合并到一个可再发行的 .dll 中。一切正常,但 EntLib5 除外。当我尝试获取记录器时,我收到此异常:

System.TypeLoadException was unhandled by user code
  Message=Inheritance security rules violated while overriding member: 'Microsoft.Practices.Unity.ResolutionFailedException.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.
  Source=My.Common.Compacted
  TypeName=Microsoft.Practices.Unity.ResolutionFailedException.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)
  StackTrace:
       at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides)
       at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, String name, IEnumerable`1 resolverOverrides) in :line 0
       at Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name, ResolverOverride[] resolverOverrides) in :line 0
       at Microsoft.Practices.Unity.UnityContainerExtensions.Resolve[T](IUnityContainer container, ResolverOverride[] overrides) in :line 0
       at Microsoft.Practices.Unity.UnityContainerExtensions.AddNewExtension[TExtension](IUnityContainer container) in :line 0
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Unity.UnityContainerExtensions.AddNewExtensionIfNotPresent[TExtension](IUnityContainer container) in :line 0
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.Unity.UnityContainerConfigurator..ctor(IUnityContainer container) in :line 0
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.CreateDefaultContainer(IConfigurationSource configurationSource) in :line 0
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.CreateDefaultContainer() in :line 0
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.SetCurrentContainerIfNotSet() in :line 0
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.get_Current() in :line 0
       at My.Common.Diagnostics.Logger..ctor(Boolean failSilently) in D:\TFS Source\My.COMMON\Framework4.0\My.Common\Diagnostics\Logger.cs:line 35
       at My.Common.Tests.LoggerTest.LoggerTestMethod() in D:\TFS Source\My.COMMON\Framework4.0\My.Common.Tests\LoggerTests.cs:line 21
  InnerException: 

我已在此处读到该异常来自 .NET4,因为现在它在编码安全性方面更加严格,但我能做什么?下载 EntLib 5 源代码并自行修复?

有什么办法可以禁用该检查吗?

我已按此顺序合并文件,也许顺序错误:

"$(TargetDir)My.Common.dll" 
"$(TargetDir)Microsoft.Practices.ServiceLocation.dll" 
"$(TargetDir)Microsoft.Practices.Unity.dll" 
"$(TargetDir)Microsoft.Practices.Unity.Interception.dll" 
"$(TargetDir)Microsoft.Practices.EnterpriseLibrary.Common.dll" 
"$(TargetDir)Microsoft.Practices.EnterpriseLibrary.Logging.dll"

干杯。

I'm using EntLib 5.0 with .NET 4. It was working, but now I've used ILMerge in order to merge all the dlls in one redistributable .dll. Everything works but EntLib5. When I try to get a logger, I get this exception:

System.TypeLoadException was unhandled by user code
  Message=Inheritance security rules violated while overriding member: 'Microsoft.Practices.Unity.ResolutionFailedException.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.
  Source=My.Common.Compacted
  TypeName=Microsoft.Practices.Unity.ResolutionFailedException.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)
  StackTrace:
       at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides)
       at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, String name, IEnumerable`1 resolverOverrides) in :line 0
       at Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name, ResolverOverride[] resolverOverrides) in :line 0
       at Microsoft.Practices.Unity.UnityContainerExtensions.Resolve[T](IUnityContainer container, ResolverOverride[] overrides) in :line 0
       at Microsoft.Practices.Unity.UnityContainerExtensions.AddNewExtension[TExtension](IUnityContainer container) in :line 0
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Unity.UnityContainerExtensions.AddNewExtensionIfNotPresent[TExtension](IUnityContainer container) in :line 0
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.Unity.UnityContainerConfigurator..ctor(IUnityContainer container) in :line 0
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.CreateDefaultContainer(IConfigurationSource configurationSource) in :line 0
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.CreateDefaultContainer() in :line 0
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.SetCurrentContainerIfNotSet() in :line 0
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.get_Current() in :line 0
       at My.Common.Diagnostics.Logger..ctor(Boolean failSilently) in D:\TFS Source\My.COMMON\Framework4.0\My.Common\Diagnostics\Logger.cs:line 35
       at My.Common.Tests.LoggerTest.LoggerTestMethod() in D:\TFS Source\My.COMMON\Framework4.0\My.Common.Tests\LoggerTests.cs:line 21
  InnerException: 

I've read here in SO that that exception comes from .NET4 because now it's more strict in terms of coding security, but what can I do? download the EntLib 5 source code and fix it myself?

Is there any way to disable that check?

I've merged the files in this order, maybe it's the wrong order:

"$(TargetDir)My.Common.dll" 
"$(TargetDir)Microsoft.Practices.ServiceLocation.dll" 
"$(TargetDir)Microsoft.Practices.Unity.dll" 
"$(TargetDir)Microsoft.Practices.Unity.Interception.dll" 
"$(TargetDir)Microsoft.Practices.EnterpriseLibrary.Common.dll" 
"$(TargetDir)Microsoft.Practices.EnterpriseLibrary.Logging.dll"

Cheers.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文