1

我知道关于这个主题已经有一些问题,但我仍然错过了导致这个错误的东西。我安装了 ninject.mvc3 包,它安装了 ninject 和 ninject.web.common 包。global.asax 中没有进行任何修改(如官方文档中所建议的那样)。

App_Start/NinjectWebCommon.csRegisterServices方法有Bind加载后的语句Kernel。当我尝试运行该站点时,此堆栈跟踪出现此错误。

[InvalidOperationException: Sequence contains no elements]
   System.Linq.Enumerable.Single(IEnumerable`1 source) +379
   Ninject.Web.Mvc.NinjectMvcHttpApplicationPlugin.Start() in c:\Projects\Ninject\ninject.web.mvc\mvc3\src\Ninject.Web.Mvc\NinjectMvcHttpApplicationPlugin.cs:53
   Ninject.Infrastructure.Language.ExtensionsForIEnumerableOfT.Map(IEnumerable`1 series, Action`1 action) in c:\Projects\Ninject\ninject\src\Ninject\Infrastructure\Language\ExtensionsForIEnumerableOfT.cs:32
   Ninject.Web.Common.Bootstrapper.Initialize(Func`1 createKernelCallback) in c:\Projects\Ninject\Ninject.Web.Common\src\Ninject.Web.Common\Bootstrapper.cs:53
   Ninject.Web.Common.NinjectHttpApplication.Application_Start() in c:\Projects\Ninject\Ninject.Web.Common\src\Ninject.Web.Common\NinjectHttpApplication.cs:81

[HttpException (0x80004005): Sequence contains no elements]
   System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +12864673
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +175
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +304
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +404
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +475

[HttpException (0x80004005): Sequence contains no elements]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12881540
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12722601

我还缺少什么步骤?

4

1 回答 1

0

消息来源在第 53 行说:

ModelValidatorProviders.Providers.Remove(
    ModelValidatorProviders.Providers.OfType<DataAnnotationsModelValidatorProvider>)
    .Single());

您是否以某种方式禁止添加DataAnnotationsModelValidatorProvider? 可能不会——因此我建议你在系统中有两个相同逻辑的副本——你有 >1NinjectWebCommon.cs吗?

另一件值得尝试的事情(一般来说 - 我没有具体理由为什么它应该为你解决这个问题)是看看当你使用Include Prerelease NuGet 包时是否仍然发生同样的事情。

于 2013-04-26T08:45:00.713 回答