I've seen several issues that refer to this problem; but none seem to quite match or fix my situation. On my development machine, I'm not having any problems. When I deploy (to IIS 8.5, Server 2012 R2) I start to get the dreaded parameterless constructor error. Here's some code that I'm using.
public class ReportController : BaseController
{
public ReportController(KestrelContext ctx) : base(ctx) { }
}
The base controller that I'm deriving from is the following.....
public class BaseController : Controller
{
protected KestrelContext db;
public BaseController(KestrelContext ctx)
{
db = ctx;
}
}
And NinjectWebCommon.cs....
[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(KestrelAdmin.App_Start.NinjectWebCommon), "Start")]
[assembly: WebActivatorEx.ApplicationShutdownMethodAttribute(typeof(KestrelAdmin.App_Start.NinjectWebCommon), "Stop")]
namespace KestrelAdmin.App_Start
{
using System;
using System.Web;
using Microsoft.Web.Infrastructure.DynamicModuleHelper;
using Ninject;
using Ninject.Web.Common;
using KestrelAdmin.Models;
public static class NinjectWebCommon
{
private static readonly Bootstrapper bootstrapper = new Bootstrapper();
/// <summary>
/// Starts the application
/// </summary>
public static void Start()
{
DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule));
DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));
bootstrapper.Initialize(CreateKernel);
}
/// <summary>
/// Stops the application.
/// </summary>
public static void Stop()
{
bootstrapper.ShutDown();
}
/// <summary>
/// Creates the kernel that will manage your application.
/// </summary>
/// <returns>The created kernel.</returns>
private static IKernel CreateKernel()
{
var kernel = new StandardKernel();
try
{
kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();
RegisterServices(kernel);
return kernel;
}
catch
{
kernel.Dispose();
throw;
}
}
/// <summary>
/// Load your modules or register your services here!
/// </summary>
/// <param name="kernel">The kernel.</param>
private static void RegisterServices(IKernel kernel)
{
kernel.Bind<KestrelContext>().ToSelf().InRequestScope();
}
}
}
Target framework is .NET 4.5 all the way around -- not 4.5.x, just 4.5. Verified dependencies in packages.config. Permissions appear to be correct on all files.
Any assistance is greatly appreciated.
UPDATE: I'm completely out of ideas here. As best I can tell, when I deploy to IIS 8.5, the NinjectWebCommon class isn't successfully Initializing the NinjectHttpModule. I'm going to include my package configuration here, and hope that somebody can point me in the right direction.
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AsyncCTP" version="0.3" targetFramework="net45" />
<package id="EntityFramework" version="6.1.3" targetFramework="net45" />
<package id="jQuery" version="1.5.1" />
<package id="jQuery.UI.Combined" version="1.8.11" />
<package id="jQuery.Validation" version="1.8.0" />
<package id="jQuery.vsdoc" version="1.5.1" />
<package id="log4net" version="2.0.3" targetFramework="net45" />
<package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.WebHost" version="5.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.WebPages.Data" version="3.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.WebPages.WebData" version="3.2.3" targetFramework="net45" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
<package id="Modernizr" version="1.7" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
<package id="Ninject" version="3.2.0.0" targetFramework="net45" />
<package id="Ninject.MVC5" version="3.2.1.0" targetFramework="net45" />
<package id="Ninject.Web.Common" version="3.2.0.0" targetFramework="net45" />
<package id="Ninject.Web.Common.WebHost" version="3.2.3.0" targetFramework="net45" />
<package id="Ninject.Web.WebApi" version="3.2.4.0" targetFramework="net45" />
<package id="Ninject.Web.WebApi.WebHost" version="3.2.4.0" targetFramework="net45" />
<package id="WebActivatorEx" version="2.0.6" targetFramework="net45" />
<package id="ZendeskApi_v2" version="3.0.20.0" targetFramework="net45" />
</packages>
Also, I tried the alternative setup described here (with the github binaries) but this resulted in the same error. So now I'm really confused.