0

当我使用 Ninject 运行我的 ASP.NET MVC 3 应用程序时,它运行良好,但是当我将它部署到 IIS 上时,它会出现以下错误:

[NullReferenceException: Object reference not set to an instance of an object.]
   Betolto.Controllers.DataInputController..ctor() +47
   DynamicInjector7922fd15a4fb4caba8ffb4cc7f18cbcf(Object[] ) +42
   Ninject.Activation.Providers.StandardProvider.Create(IContext context) +489
   Ninject.Activation.Context.Resolve() +177
   Ninject.<>c__DisplayClass10.<Resolve>b__c(IBinding binding) +30
   System.Linq.WhereSelectEnumerableIterator`2.MoveNext() +151
   System.Linq.Enumerable.SingleOrDefault(IEnumerable`1 source) +4222965
   Ninject.Web.Mvc.NinjectDependencyResolver.GetService(Type serviceType) +64
   System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +51
>
[InvalidOperationException: An error occurred when trying to create a controller of type 'Betolto.Controllers.DataInputController'. Make sure that the controller has a parameterless public constructor.]
   System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +182
   System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +80
   System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +74
   System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +232
   System.Web.Mvc.<>c__DisplayClass6.<BeginProcessRequest>b__2() +49
   System.Web.Mvc.<>c__DisplayClassb`1.<ProcessInApplicationTrust>b__a() +13
   System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
   System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
   System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Func`1 func) +124
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +98
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +50
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +16
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8969412
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184

我已经通过互联网搜索,但我没有找到解决我的问题的方法。我感谢所有的答案。

4

1 回答 1

1

从堆栈跟踪来看,问题出在控制器的 (Betolto.Controllers.DataInputController) 构造函数中。所以 NInject 可能工作正常。我的猜测是错误是由其他原因引起的,开发环境和生产环境之间的差异,可能是配置文件中缺少参数或数据库数据中的差异。添加日志记录,以便您确切知道哪一行和哪个对象是导致异常的空对象。如果您可以将调试器附加到您的生产代码中,这将加快调试速度。

于 2012-11-04T10:47:10.547 回答