Odata v4 error "Does not support untyped value in non-open type"

19,362

I've experienced this error before and it's caused by passing a property of a JSON object that doesn't exist on the data model.

For example, given the data model:

public class User
{
    public long UserId { get; set; }

    public string UserName { get; set; }
}

And an OData controller has the method:

public IHttpActionResult Post(User user)

When the following data is sent using the POST method:

{
    "UserId": "0",
    "UserName": "test",
    "UserPassword": "test"
}

Then the server will return error 400 with the following response:

{
    "error": {
        "code": "",
        "message": "The request is invalid.",
        "innererror": {
            "message": "user : Does not support untyped value in non-open type.\r\n",
            "type": "",
            "stacktrace": ""
        }
    }
}

So if the UserPassword property, in this example, is removed from the data sent using the POST method, then the error doesn't occur.

Share:
19,362
vijay daniel
Author by

vijay daniel

Updated on June 06, 2022

Comments

  • vijay daniel
    vijay daniel almost 2 years

    As I updated the model, it throws "Does not support untyped value in non-open type". It was working before the update. Unable to pin down the source of the problem. any ideas.

  • vijay daniel
    vijay daniel over 6 years
    That makes sense, had to go through a list of properties and figured out a similar reason. thanks Rami,
  • Toodoo
    Toodoo about 6 years
    Is there any ways to tell oData to ignore additionnal json property of the object ? I need some additional data in my post that are not mapped to DB. Thanks in advance.
  • Rami A.
    Rami A. about 6 years
    @Toodoo, in your case, you can try to create and use an open type, like the error message indicates.
  • Toodoo
    Toodoo about 6 years
    @RamiA.Thanks for your anwser, but I also tried open type, but get some error when using GET...