Asp.Net Web Api 2.2:空的“MediaTypeFormatter”无效

问题描述 投票:0回答:1

我在生产环境中的 Asp.Net Web Api 应用程序遇到一些问题,一些 api 请求(其中约 1%)间歇性崩溃,并显示以下异常消息:

空的“MediaTypeFormatter”无效。 参数名称:格式化程序

所有这些错误似乎都是随机发生的,在这些情况下,执行流甚至不会到达 ApiController 端点。

有人知道如何解决这个问题吗?任何帮助将不胜感激。

更多信息和完整的堆栈跟踪:

  • .Net框架4.5
  • Asp.Net Web Api 2.2(Microsoft.AspNet.WebApi 包 v5.2.3)
  • IIS 8.5
  • Windows 服务器 2012 R2
"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

  • 我们的生产环境配置是7台服务器负载 平衡器
  • 单台服务器只有一个应用程序池提供 问题
  • 回收应用程序后,问题消失了(我们 仍在调查该问题,我们不希望再次发生)。
c# .net asp.net-web-api .net-4.5
1个回答
0
投票

[@debe80] 您是否能够确定问题的根本原因? 不幸的是,我们也遇到了同样的问题。

© www.soinside.com 2019 - 2024. All rights reserved.