1

Closed

ODataEntityTypeSerializer closes connection when error happens to validate the data

description

The issue happens when some data from server side missing some required property. The validation error is:

Microsoft.Data.OData.ODataException occurred
HResult=-2146233079
Message=The property 'Name[Nullable=False]' of type 'Edm.String' has a null value, which is not allowed.
Source=Microsoft.Data.OData
StackTrace:
   at Microsoft.Data.OData.WriterValidationUtils.ValidateNullPropertyValue(IEdmProperty expectedProperty, ODataWriterBehavior writerBehavior, IEdmModel model)
InnerException:

Instead of sending back the error, server will close the connection.

The model to repro is:
public class Todo
{
    public int ID { get; set; }
    [Required]
    public string Name { get; set; }
    [Required]
    public string Name1 { get; set; }
    //[Required]
    //public string Name2 { get; set; }
    //[Required]
    //public string Name3 { get; set; }
    //[Required]
    //public string Name4 { get; set; }
    //[Required]
    //public string Name5 { get; set; }
    //[Required]
    //public string Name6 { get; set; }
    //[Required]
    //public string Name7 { get; set; }
    //[Required]
    //public string Name8 { get; set; }

    [Required]
    public Person CreatedBy { get; set; }
    public IEnumerable<Person> AssignedTo { get; set; }
}

public class Person
{
    public int ID { get; set; }
    [Required]
    public string Name { get; set; }
}
The controller is:
public class TodoesController : ApiController
{
    public IEnumerable<Todo> Get()
    {
        return new Todo[] {
            new Todo {
                ID = 0
            },
            new Todo {
                ID = 1
            }
        };
    }
We decided to punt this issue as it's related to a core Web API bug.
Closed Oct 3, 2013 at 11:35 PM by danroth27
We could return an OData in-stream error in this case, but in-stream errors are useless to most clients.

comments

HongmeiG wrote Sep 27, 2012 at 11:38 PM

We should turn off the validation here.

HongmeiG wrote Oct 26, 2012 at 1:46 AM

we should not be validate on the serialization path.

davidmatson wrote Jan 2, 2013 at 7:25 PM

There doesn't appear to be a way to do that. I'm asking the ODataLib folks about this bug.