Friday, July 29, 2016

Sequence contains no elements while using Ninject

I was recently working on an ASP.NET Web API project that used Ninject as its IoC container when I was suddenly faced with this error message:


As you can see from above, the error message provided no real insight as to what might be the root cause of the problem!

Therefore, I decided to do some further digging into the documentation for Ninject and came across this article: https://github.com/ninject/Ninject.Web.Common/wiki/Setting-up-an-IIS-hosted-web-application

Based on this documentation, I needed to make sure that my NuGet package reference to Ninject.Web.Common.WebHost was correct.

Of course, when I went into my packages.config file, the NuGet package reference was listed and it was also listed as installed in NuGet Package Manager.

However, based on the error message, I figured there was some problem with this installation and its corresponding references so I removed the line from packages.config in my Web API project and re-installed the Ninject.Web.Common.WebHost NuGet package reference.

As you can already probably guess, this did the trick for me and resolved this very elusive Ninject problem!!

NOTE:  Another time I have encountered this problem has been due to invalid assemblies in the bin folder of my ASP.NET Web API project.  Simple deleting the bin folder of my ASP.NET Web API project and rebuilding my solution also resolved the problem!

No comments:

Post a Comment