You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unable to cast object of type 'Microsoft.AspNetCore.Mvc.Abstractions.ActionDescriptor' to type 'Microsoft.AspNetCore.Mvc.Controllers.ControllerActionDescriptor'.
#137
Open
fp-jcorriveau opened this issue
May 1, 2023
· 3 comments
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.ActionDescriptorinternalstaticActionResultToActionResult(thisControllerBasecontroller,Ardalis.Result.IResultresult){IDictionary<object,object>properties=controller.ControllerContext.ActionDescriptor.Properties;ResultStatusOptionsresultStatusOptions=(properties.ContainsKey((object)"ResultStatusMap")?properties[(object)"ResultStatusMap"]asResultStatusMap:newResultStatusMap().AddDefaultMap())[result.Status];intstatusCode=(int)resultStatusOptions.GetStatusCode(controller.HttpContext.Request.Method);returnresult.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.ControlleContextpublicnewControllerActionDescriptorActionDescriptor{get{return(ControllerActionDescriptor)base.ActionDescriptor;}set{base.ActionDescriptor=value;}}
The text was updated successfully, but these errors were encountered:
I don't have the problem when using .WithResult<Result<T>> along with the attribute [TranslateResultToActionResult] instead of .WithActionResult and ToActionResult
// Is ok[TranslateResultToActionResult]publicclassMyEndpoint:EndpointBaseAsync.WithoutRequest.WithResult<Result<MyResult>>{[HttpPost("/api/my-endpoint")][ProducesResponseType(StatusCodes.Status200OK)]publicoverrideasyncTask<Result<MyResult>>HandleAsync(CancellationTokencancellationToken=newCancellationToken()){returnawait_service.DoSomething();}}
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
The text was updated successfully, but these errors were encountered: