使用EntLib 5.0和.NET 4重写成员时,违反了继承安全规则

时间:2011-02-14 12:45:20

标签: .net .net-4.0 enterprise-library ilmerge

我正在使用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"

干杯。

1 个答案:

答案 0 :(得分:2)