拥有这些 POCO:
public class UserRegistration
{
[Required]
public ApiKey ApiKey { get; set; }
...
}
public class ApiKey
{
[Required]
public Guid AppKey { get; set; }
...
}
这个Json:
{
"apiKey": {
"appKey": "D8B4DE20-5654-43B0-B3F6-FDA416087FDE"
}
}
我遇到了一个例外:
System.InvalidCastException: Unable to cast object of type 'System.Guid' to type 'System.String'.
at System.Web.Http.ApiController.d__b.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__0.MoveNext()
将此称为 ASP.NET Web API 控制器:
public HttpResponseMessage Put([FromBody]UserRegistration userRegistration)
{
}
如果将属性类型从 Guid 更改为字符串,一切正常,但我想要 Guid。是否支持这样的场景?