【发布时间】:2014-03-11 17:23:39
【问题描述】:
我的 WebApp 是 WebForms 页面和 MVC 4 页面的组合。
使用 Unity,我遇到以下异常。
异常类型:
Microsoft.Practices.Unity.ResolutionFailedException, Microsoft.Practices.Unity, Version=2.1.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
消息:
Resolution of the dependency failed, type = "System.Web.Mvc.ModelMetadataProvider", name = "(none)". Exception occurred while: while resolving. Exception is: InvalidOperationException - The type ModelMetadataProvider does not have an accessible constructor. At the time of the exception, the container was:
Resolving System.Web.Mvc.ModelMetadataProvider,(none)
带有Inner Exception 的:
消息:
The type ModelMetadataProvider does not have an accessible constructor.
堆栈跟踪:
at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.ThrowForNullExistingObje ct(IBuilderContext context)
at BuildUp_System.Web.Mvc.ModelMetadataProvider(IBuilderContext )
at Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context)
at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context)
at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)
at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides)
对于以下类型,我始终得到相同的分辨率异常:
System.Web.Mvc.ITempDataProvide
System.Web.Mvc.Async.IAsyncActionInvoker
System.Web.Mvc.IActionInvoker
System.Web.Mvc.ModelMetadataProvider
System.Web.Mvc.IViewPageActivator
在 Application_Start 中,我正在设置 IoC:
DependencyResolver.SetResolver(new UnityDependencyResolver(UnityConfigurator.GetContainer()));
...其中GetContainer返回所有注册类型,UnityDependencyResolver是-a IDependencyResolver
任何想法是什么导致了这个问题?
谢谢,
--埃德
【问题讨论】:
-
你有旅游统一配置吗?你是否为 MVC 设置了依赖解析器?
标签: c# asp.net .net asp.net-mvc-4 unity-container