我正在尝试运行 从 codeplex 下载的MVC 示例项目Shrinkr
我实际上在VS2012中打开了这个解决方案并且编译成功。但是当我运行这个应用程序时,我得到了这个错误。
我收到一条异常错误消息,指出“尝试获取 IUserRepository 类型的实例时发生激活错误,密钥“”“
下面粘贴的是详细的异常消息
Microsoft.Practices.ServiceLocation.ActivationException was unhandled by user code
HResult=-2146233088
Message=Activation error occured while trying to get instance of type IUserRepository, key ""
Source=Microsoft.Practices.ServiceLocation
StackTrace:
at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)
at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance[TService]()
at Shrinkr.Web.CreateDefaultUsers.ExecuteCore(IServiceLocator serviceLocator) in c:\Users\RON\Downloads\Shrinkr\Shrinkr.Web.Common\BootstrapperTask\CreateDefaultUsers.cs:line 19
at System.Web.Mvc.Extensibility.BootstrapperTask.Execute(IServiceLocator serviceLocator)
at System.Web.Mvc.Extensibility.Bootstrapper.Execute()
at System.Web.Mvc.Extensibility.ExtendedMvcApplication.Application_Start()
InnerException: Microsoft.Practices.Unity.ResolutionFailedException
HResult=-2146233088
Message=Resolution of the dependency failed, type = "Shrinkr.Repositories.IUserRepository", name = "". Exception message is: The current build operation (build key Build Key[Shrinkr.Infrastructure.EntityFramework.UserRepository, null]) failed: The parameter databaseFactory could not be resolved when attempting to call constructor Shrinkr.Infrastructure.EntityFramework.UserRepository(Shrinkr.Infrastructure.EntityFramework.IDatabaseFactory databaseFactory, Shrinkr.Infrastructure.EntityFramework.IQueryFactory queryFactory). (Strategy type BuildPlanStrategy, index 3)
Source=Microsoft.Practices.Unity
TypeRequested=IUserRepository
StackTrace:
at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name)
at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, String name)
at Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name)
at Microsoft.Practices.Unity.UnityContainerBase.Resolve(Type t)
at System.Web.Mvc.Extensibility.Unity.UnityAdapter.DoGetInstance(Type serviceType, String key)
at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)
InnerException: Microsoft.Practices.ObjectBuilder2.BuildFailedException
HResult=-2146233088
Message=The current build operation (build key Build Key[Shrinkr.Infrastructure.EntityFramework.UserRepository, null]) failed: The parameter databaseFactory could not be resolved when attempting to call constructor Shrinkr.Infrastructure.EntityFramework.UserRepository(Shrinkr.Infrastructure.EntityFramework.IDatabaseFactory databaseFactory, Shrinkr.Infrastructure.EntityFramework.IQueryFactory queryFactory). (Strategy type BuildPlanStrategy, index 3)
Source=Microsoft.Practices.ObjectBuilder2
BuildKey=Build Key[Shrinkr.Infrastructure.EntityFramework.UserRepository, null]
ExecutingStrategyIndex=3
ExecutingStrategyTypeName=BuildPlanStrategy
StackTrace:
at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)
at Microsoft.Practices.ObjectBuilder2.Builder.BuildUp(IReadWriteLocator locator, ILifetimeContainer lifetime, IPolicyList policies, IStrategyChain strategies, Object buildKey, Object existing)
at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name)
InnerException: System.InvalidOperationException
HResult=-2146233079
Message=The parameter databaseFactory could not be resolved when attempting to call constructor Shrinkr.Infrastructure.EntityFramework.UserRepository(Shrinkr.Infrastructure.EntityFramework.IDatabaseFactory databaseFactory, Shrinkr.Infrastructure.EntityFramework.IQueryFactory queryFactory).
Source=Microsoft.Practices.ObjectBuilder2
StackTrace:
at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.ThrowForResolutionFailed(Exception inner, String parameterName, String constructorSignature, IBuilderContext context)
at BuildUp_Shrinkr.Infrastructure.EntityFramework.UserRepository(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)
InnerException: Microsoft.Practices.ObjectBuilder2.BuildFailedException
感谢您的建议,使其工作