Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebAPI PUT InsufficientExecutionStackException with DbGeography Type

When handling a PUT call, a WebAPI handler seems to go into a stack overflow type situation when validating the model. The exception isn't clear, and there is no indication as to what in the model is causing this validation class to go into a loop. Attaching the debugger does nothing. The handler will never get called, the serializer will deserialize the posted json normally without incident. What could be wrong?

The following code just loops several hundred times before exiting throwing the exception"

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) 

The Model is akin to this simple example. The model has default values which I can confirm are all initialized. The model also has no references to itself.

public class Example {
  [Required]
  public string test {get; set;}

  [Required]
  public CustomEnumType myEnum {get; set;}
}
like image 685
simbolo Avatar asked Jan 16 '15 08:01

simbolo


1 Answers

Found solution in: Exclude a type from model validation (example DbGeography) to avoid InsufficientExecutionStackException

One of the types on this model is DbGeography. The default validator for some reason gets stuck in a loop inside this type enumerating it's properties. The validator shouldn't even be in there and seems to be a bug. But the behaviour can be overwridden with a custom validator set to ignore this type.

like image 98
simbolo Avatar answered Nov 07 '22 17:11

simbolo