ardalis/Result

Unable to cast object of type 'Microsoft.AspNetCore.Mvc.Abstractions.ActionDescriptor' to type 'Microsoft.AspNetCore.Mvc.Controllers.ControllerActionDescriptor'.

Open

#137 建立於 2023年5月1日

在 GitHub 查看
 (3 留言) (0 反應) (0 負責人)C# (126 fork)github user discovery
bughelp wanted

倉庫指標

Star
 (1,034 star)
PR 合併指標
 (PR 指標待抓取)

描述

Since the version 7.0.0, I get an exception

Unable to cast object of type 'Microsoft.AspNetCore.Mvc.Abstractions.ActionDescriptor' to type 'Microsoft.AspNetCore.Mvc.Controllers.ControllerActionDescriptor'.

If I rollback to 4.0.2, everything seems fine. I can see the method has changed, I don't know if it's an issue with the controllers configuration

// fails when accessing controller.ControllerContext.ActionDescriptor

internal static ActionResult ToActionResult(this ControllerBase controller, Ardalis.Result.IResult result)
    {
      IDictionary<object, object> properties = controller.ControllerContext.ActionDescriptor.Properties;
      ResultStatusOptions resultStatusOptions = (properties.ContainsKey((object) "ResultStatusMap") ? properties[(object) "ResultStatusMap"] as ResultStatusMap : new ResultStatusMap().AddDefaultMap())[result.Status];
      int statusCode = (int) resultStatusOptions.GetStatusCode(controller.HttpContext.Request.Method);
      return result.Status == ResultStatus.Ok ? (!typeof (Ardalis.Result.Result).IsInstanceOfType((object) result) ? (ActionResult) controller.StatusCode(statusCode, result.GetValue()) : (ActionResult) controller.StatusCode(statusCode)) : (!(resultStatusOptions.ResponseType == (Type) null) ? (ActionResult) controller.StatusCode(statusCode, resultStatusOptions.GetResponseObject(controller, result)) : (ActionResult) controller.StatusCode(statusCode));
    }
   // The property is being cast here 
   // Microsoft.AspNetCore.Mvc.ControlleContext
    public new ControllerActionDescriptor ActionDescriptor
    {
        get { return (ControllerActionDescriptor)base.ActionDescriptor; }
        set { base.ActionDescriptor = value; }
    }

貢獻者指南