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

这一生的挚爱 提交于 2019-12-08 15:00:02

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/45948893/odata-v4-error-does-not-support-untyped-value-in-non-open-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!