我正在使用 Enterprise Library 6 和 Unity v.3.5.0.0
出现以下错误:
无法从程序集“Microsoft.Practices.EnterpriseLibrary.Common,版本=6.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35”加载类型“Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Manageability.ConfigurationSectionManageabilityProviderAttribute”。
当使用此代码通过使用一组规则和约定(通过约定注册)向容器自动注册多种类型时
container.RegisterTypes(
AllClasses.FromLoadedAssemblies()
.Where(x => (x.IsPublic == true) &&
(x.GetInterfaces().Any() == true) &&
(x.IsAbstract == false) &&
(x.IsClass == true) &&
x.Namespace == "Company.Project.Data.DA.NW" ),
WithMappings.FromAllInterfaces, type => (container.Registrations.Select(x => x.RegisteredType)
.Any(r => type.GetInterfaces().Contains(r) == true) == true) ? WithName.TypeName(type) : WithName.Default(type),
WithLifetime.Transient);
更新:
类型:
Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Manageability.ConfigurationSectionManageabilityProviderAttribute
不再是 EntLib 6 的一部分,而是在 Entlib 5 中。
堆栈跟踪:
[TypeLoadException:无法从程序集“Microsoft.Practices.EnterpriseLibrary.Common,版本=6.0.0.0,文化=中性,PublicKeyToken=31bf3856ad364e35”中加载类型“Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Manageability.ConfigurationSectionManageabilityProviderAttribute”。]
系统.ModuleHandle.ResolveType(RuntimeModule 模块, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type) +0
System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] type[] RuntimeTypeHandle[] typeInstantiationHandle方法实例化上下文)+145
System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments) +162
System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg) +87
System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent) +438 System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType) +103
System.Reflection .RuntimeAssembly.GetCustomAttributes(Type attributeType, Boolean inherit) +64
System.Attribute.GetCustomAttributes(Assembly element, Type attributeType, Boolean inherit) +87
System.Attribute.GetCustomAttribute(Assembly element, Type attributeType, Boolean inherit) +13
System.Reflection .CustomAttributeExtensions.GetCustomAttribute(装配元素)+57
Microsoft.Practices.Unity.AllClasses.IsSystemAssembly(Assembly a) +78 Microsoft.Practices.Unity.<>c__DisplayClass10.b__f(Assembly a) +72 System.Linq.WhereArrayIterator 2.MoveNext() +168 System.Linq.WhereEnumerableIterator 1类型,Func 2 getName,Func 2 getInjectionMembers,布尔覆盖 ExistingMappings)+13231.MoveNext() +48
System.Linq.<SelectManyIterator>d__141.MoveNext() +152
Microsoft.Practices.Unity.UnityContainerRegistrationByConventionExtensions.RegisterTypes(IUnityContainer container, IEnumerable2 getFromTypes, Func
2 getLifetimeManager, Func