로컬에서 작동하는 .net 4.5.1을 사용하는 MVC 4 웹 응용 프로그램이 있는데 라이브 서버에 사이트를 배포하면 예외가 발생합니다 컨트롤러를 호출 할 때 예외가 발생합니다. 컨트롤러에 생성자를 넣을 때 예외가 throw됩니다. 컨트롤러에서 생성자를 제거하여 응용 프로그램을 테스트 했으므로 제대로 작동합니다. 왜 이런 일이 발생하는지 파악할 수 없습니다.asp.net mvc 응용 프로그램에서 응용 프로그램을 배포 할 때 컨트롤러 예외가 발생합니다.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
소스 오류 : 여기
namespace Test.Controllers
{
public class TestController : Controller
{
private readonly ICountryService _countryService;
public TestController()
{
_countryService=new CountryService();
}
// GET: /Test/
public ActionResult Index()
{
var items = _countryService.GetAllCountries();
return View(items.ToList());
}
}
}
예외입니다 :
여기 내 컨트롤러
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.] Test.Controllers.TestController..ctor() +74
[TargetInvocationException: Exception has been thrown by the target of an invocation.] System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0 System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +113 System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +232 System.Activator.CreateInstance(Type type, Boolean nonPublic) +83 System.Activator.CreateInstance(Type type) +6 System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +55
[InvalidOperationException: An error occurred when trying to create a controller of type 'Test.Controllers.TestController'. Make sure that the controller has a parameterless public constructor.] System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +178 System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +77 System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +66 System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +191 System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +50 System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +48 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +16 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +301 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
나는 라이브 서버에 웹 사이트를 배포 할 때 이런 일이 왜
.도움을 주시면 감사하겠습니다. 이 질문에 답변하기 위해 다른 정보가 필요하면 알려주십시오.
가능한 중복 :
NinjectWebCommon.cs :
여기 Ninject에를 사용하여 의존성 주입을하는 방법 어떻게 해결할 수 있습니까?] (http://stackoverflow.com/questions/4660142/what-is-a-nul lreferenceexception-and-how-do-i-fix-it) –
아마도'Response'는 null입니까? – Johan