我在生产环境中的 Asp.Net Web Api 应用程序遇到一些问题,一些 api 请求(其中约 1%)间歇性崩溃,并显示以下异常消息:
空的“MediaTypeFormatter”无效。 参数名称:格式化程序
所有这些错误似乎都是随机发生的,在这些情况下,执行流甚至不会到达 ApiController 端点。
有人知道如何解决这个问题吗?任何帮助将不胜感激。
更多信息和完整的堆栈跟踪:
"ExceptionMessage": "A null 'MediaTypeFormatter' is not valid.
Parameter name: formatters",
"ExceptionType": "System.ArgumentException",
"StackTrace": " at System.Net.Http.Formatting.MediaTypeFormatterCollection.VerifyAndSetFormatters(IEnumerable'1 formatters)
at System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent content, Type type, IEnumerable'1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)
at System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync(HttpRequestMessage request, Type type, IEnumerable'1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)
at System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync(HttpRequestMessage request, Type type, IEnumerable'1 formatters, IFormatterLogger formatterLogger)
at System.Web.Http.ModelBinding.FormatterParameterBinding.<ExecuteBindingAsyncCore>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Controllers.HttpActionBinding.<ExecuteBindingAsyncCore>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
编辑 04/05/2020
[@debe80] 您是否能够确定问题的根本原因? 不幸的是,我们也遇到了同样的问题。