I have a single VS2010 solution with a Web.Api project and an MVC 3 project.

Both the Web.APi and the MVC project have their own App_Start with NinjectWebCommon in and their own bindings declared in there.

When trying to use the Api I always get the following message:

Sequence contains no elements

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Sequence contains no elements

Source Error:

Line 30: DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule)); Line 31: DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule)); Line 32: bootstrapper.Initialize(CreateKernel); Line 33: } Line 34:

Source File: D:\Code\GreenDeal\PoS\GreenDeal.UI\App_Start\NinjectWebCommon.cs Line: 32

Stack Trace:

[InvalidOperationException: Sequence contains no elements] System.Linq.Enumerable.Single(IEnumerable1 source) +371 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(IEnumerable1 series, Action1 action) in c:\Projects\Ninject\ninject\src\Ninject\Infrastructure\Language\ExtensionsForIEnumerableOfT.cs:32 Ninject.Web.Common.Bootstrapper.Initialize(Func1 createKernelCallback) in c:\Projects\Ninject\Ninject.Web.Common\src\Ninject.Web.Common\Bootstrapper.cs:53 XXXX.UI.App_Start.NinjectWebCommon.Start() in D:\Code\XXXX\PoS\XXXX.UI\App_Start\NinjectWebCommon.cs:32

I do not get this error if I remove the WebActivator.PreApplicationStartMethod from the Api or the MVC site.

I presume there is an issue with having the two Starts but am not sure what to do? Can I make them co-exist? Should I split into 2 solutions and hope it goes away? When deployed the site and the api will reside on separate servers and the site will consume the api.

有帮助吗?

解决方案

Went back to basics.

Followed the steps defined in here: http://www.eyecatch.no/blog/2012/06/using-ninject-with-webapi-rc/

Still had issues but that was because the MVC, client site had a reference to ninject.webapi. Removed that and all works.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top