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.
Fixed.
http://entlib.codeplex.com/discussions/245946