WebAPI PUT InsufficientExecutionStackException 与 DbGeography 类型
WebAPI PUT InsufficientExecutionStackException with DbGeography Type
在处理 PUT 调用时,WebAPI 处理程序在验证模型时似乎会进入堆栈溢出类型的情况。异常不明确,也没有迹象表明模型中的什么导致此验证 class 进入循环。附加调试器没有任何作用。永远不会调用处理程序,序列化程序将正常反序列化发布的 json 而不会发生意外。 有什么问题吗?
下面的代码只是循环了几百次才退出抛出异常
Insufficient stack to continue executing the program safely. This can
happen from having too many functions on the call stack or function on
the stack using too much stack space.
at System.Runtime.CompilerServices.RuntimeHelpers.EnsureSufficientExecutionStack()
at System.Web.Http.Validation.DefaultBodyModelValidator.ValidateNodeAndChildren(ModelMetadata metadata, ValidationContext validationContext, Object container, IEnumerable`1 validators)
at System.Web.Http.Validation.DefaultBodyModelValidator.ValidateProperties(ModelMetadata metadata, ValidationContext validationContext)
模型类似于这个简单的例子。该模型具有默认值,我可以确认这些默认值均已初始化。该模型也没有对自身的引用。
public class Example {
[Required]
public string test {get; set;}
[Required]
public CustomEnumType myEnum {get; set;}
}
在以下位置找到解决方案:Exclude a type from model validation (example DbGeography) to avoid InsufficientExecutionStackException
此模型的其中一种类型是 DbGeography
。由于某种原因,默认验证器陷入此类型内的循环中,枚举其属性。验证器甚至不应该在那里并且似乎是一个错误。但是可以使用设置为忽略此类型的自定义验证器来覆盖该行为。
在处理 PUT 调用时,WebAPI 处理程序在验证模型时似乎会进入堆栈溢出类型的情况。异常不明确,也没有迹象表明模型中的什么导致此验证 class 进入循环。附加调试器没有任何作用。永远不会调用处理程序,序列化程序将正常反序列化发布的 json 而不会发生意外。 有什么问题吗?
下面的代码只是循环了几百次才退出抛出异常
Insufficient stack to continue executing the program safely. This can happen from having too many functions on the call stack or function on the stack using too much stack space.
at System.Runtime.CompilerServices.RuntimeHelpers.EnsureSufficientExecutionStack()
at System.Web.Http.Validation.DefaultBodyModelValidator.ValidateNodeAndChildren(ModelMetadata metadata, ValidationContext validationContext, Object container, IEnumerable`1 validators)
at System.Web.Http.Validation.DefaultBodyModelValidator.ValidateProperties(ModelMetadata metadata, ValidationContext validationContext)
模型类似于这个简单的例子。该模型具有默认值,我可以确认这些默认值均已初始化。该模型也没有对自身的引用。
public class Example {
[Required]
public string test {get; set;}
[Required]
public CustomEnumType myEnum {get; set;}
}
在以下位置找到解决方案:Exclude a type from model validation (example DbGeography) to avoid InsufficientExecutionStackException
此模型的其中一种类型是 DbGeography
。由于某种原因,默认验证器陷入此类型内的循环中,枚举其属性。验证器甚至不应该在那里并且似乎是一个错误。但是可以使用设置为忽略此类型的自定义验证器来覆盖该行为。