2012-05-08 88 views
0

我有一個MVC應用程序,它有兩個基本蹤跡,即時知道爲什麼有兩個人的關係嗎?..堆棧跟蹤是什麼意思,當他們有兩個?

[MissingMethodException: No parameterless constructor defined for this object.] 
    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) +98 
    System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) +241 
    System.Activator.CreateInstance(Type type, Boolean nonPublic) +69 
    System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +67 

[InvalidOperationException: An error occurred when trying to create a controller of type 'PteDotNet.Web.Controllers.BlogController'. 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() +8970356 
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184 

回答

0

一個是內部異常的堆棧跟蹤。

它看起來像你第一次得到了MissingMethodException,以理

此對象定義無參數的構造函數。

這引起了InvalidOperationException,以理

試圖創建類型的控制裝置「PteDotNet.Web.Controllers.BlogController」時發生錯誤。確保控制器有一個無參數的公共構造函數。

所以顯然你的BlogController需要一個無參數的構造函數。

0

我'不能完全肯定,但它看起來像根本原因:由於第一Exceptin

0

InvalidOperationException

MissingMethodException首先被燒成,然後InvalidOperationException被炒魷魚,是拋出的異常,但它是由MissingMethodException引起的,並且該例外包含在InvalidOperationExceptionInnerException中。 InvalidOperationException解釋什麼地方出了問題,但看着InnerException你可以看到首先觸發失敗的地方。

當您對帶有內部異常的異常評估ToString()時,您會獲得所有嵌套內部異常的堆棧跟蹤,以幫助您理解問題。一個常見的錯誤是將ex.Message + ex.StackTrace用於診斷目的,但是會丟失關於內部異常的信息。除非您想隱藏這些有價值的信息,否則在記錄異常時應始終使用ex.ToString()

在MVC框架中有類似下面的代碼:

try { 
    // Will throw MissingMethodException if there is no parameterless constructor. 
    var controller = Activator.CreateInstance(type); 
    ... 
} 
catch (MissingMethodException ex) { 
    var message = String.Format("An error occurred when trying to create a controller of type '{0}'. Make sure that the controller has a parameterless public constructor.", type); 
    throw new InvalidOperationException(message, ex); 
} 

因此,而不是得到一個MissingMethodException這可能會迷惑你,你得到一個很好的解釋了InvalidOperationException。當涉及異常處理時,這是最佳實踐的一個例子。

相關問題