Tuesday 15 June 2010

ASP.Net Web API: Formatter Parameter Binding exception -


I have a data contract that accepts my web API behavior method as an action parameter.

  public Actiteepiarpispasmess Post My object (Mayobjektarkwastdisi Objearaijest) {...} [data Kantrokt] public class MyObjectRequestDc {public MyObjectRequestDc () {context = new List & lt; Uri & gt; (); } [Datamember] public list & lt; Uri & gt; Reference {Receive; Set; }}   

One of the properties of the contract is a list of the URI objects ('context').

If the client never submits a request that contains the string that does not solve any of the URI, an exception Framework is thrown deep within the code (because it instantiate the URI class given string Can not):

Example Jason Input:

{"Reference": ["This is not a valid Yuri." ]}

Exception Details / Stack Trace

  Error Description: System. Unknown Operation Exception: This operation is not supported for any relative URIs. GetAbsolutePathFromUri (object) system on system.Uri.get_AbsolutePath () Web.Http.Metadata.Providers.AssociatedMetadataProvider`1 & Lt; & Gt; C__DisplayClass3 & Lt; GetMetadataForPropertiesImpl & gt; B__0 () at System.Web.Http.Validation. DefaultBodyModelValidator.ValidateNodeAndChildren (ModelMetadata metadata, ValidationContext validationContext, object container) on System.Web.Http.Validation.DefaultBodyModelValidator.ValidateProperties (ModelMetadata metadata, ValidationContext validationContext) (ModelMetadata metadata System.Web.Http.Validation.DefaultBodyModelValidator.ValidateNodeAndChildren, ValidationContext validationContext System.Web.Http.Validation.DefaultBodyModelValidator.ValidateElements (on the IEnumerable model, ValidationContext validationContext) on System.Web.Http.Validation.DefaultBodyModelValidator.ValidateNodeAndChildren (ModelMetadata Metadata, ValidationContext validationContext, Object Container) on System.Web .Validation.DefaultBodyModelValidator System.Web.Http.ModelBinding.FormatterParameterBinding on S ystem.Web.Http.Validation.DefaultBodyModelValidator.ValidateNodeAndChildren (ModelMetadata metadata, Manykrncontekst verification, the object container object container) ValidateProperties (ModelMetadata metadata validation Kantast verification). & Lt; & Gt; C__DisplayClass1. & Lt; ExecuteBindingAsync & gt; on System.Threading.Task B__0 (object model). Tasks.TaskHelpersExtensions. & Lt; & Gt; C__DisplayClass49. & Lt; ToAsyncVoidTask & gt; B__48 () on system threading. Tasks. The TaskHelpers.RunSynchronously [TResult] (Func11 func, Token cancellation token to cancel)   

Need Response to that user code may be returned with 400 (Baderekwast) and "referenced URI xxx ' a message on the lines is not valid.

at the moment, an exception has been caught by Global Akspasnfiltr and returned a useless 500.

ideally, I model a model state Error or any other mechanism should occupy me as a dispute Area will allow L reaction.

options I considered: 1. Create a custom Actiteepeepimetrybing class and experience to handle the exception? 2. Change reference properties for a list of String objects and then controller 3 Holding the exception in GlobalExceptionFilter and Tailor feedback from here (it's rank code smell though ...)

Most of the suggestions More welcome!

This is a bug in the web API when it is always always fails when type But any public property throws at.

It has already been fixed in our current bits: and fixes should be available in our next release.

If you disable such verification as a workaround:

  config.Services.Clear (typeof (ModelValidatorProvider));   

You may get better behavior with an invalid model status.

No comments:

Post a Comment