Skip to content

Binding error passes silently #55

Description

@neistow

I've stumbled upon an odd behaviour with hybrid model binding. Consider this example:

Model:

public class AnotherDto
{
    public string SomeString { get; set; }
    public int  SomeInt { get; set: }
}

public class MyDto
{
    public string SomeString { get; set; }
    public DateTime SomeDateTime { get; set; }
    public AnotherDto SomeNestedDto { get; set; }
}

Controller endpoint:

public IActionResult SomeEndpoint([FromHybrid] MyDto dto)
{
    // code here...
}

Request:

{
    "someString" : "str",
    "someDateTime": "*imagine this is a valid datetime*"
    "someNestedDto": { "someProperty": 123, "anotherProperty": "..." }
}

In the request property "someNestedDto" has INTENTIONALLY a wrong type.

Behaviour: dto that comes to my controller method has empty fields with default values.

Expected behaviour: parse error. If this happens with [FromBody] attribute applied to MyDto, then a parse exception will be raised.

As for me such errors shouldn't pass silently.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions