当我将应用程序的servicestack版本升级为“4.5.12”时,我收到如下所述的错误。
首先,我的应用程序配置基本上是这样的:
[Route("/users/{Id}")]
public class User : IReturn<UserResponse>
{
public int Id { get; set; }
public string Name { get; set; }
}
public class UserResponse
{
public int Id { get; set; }
public string Name { get; set; }
public string Surname { get; set; }
}
public class MyServices : Service
{
public object Any(User request)
{
return new UserResponse { Id = request.Id, Name = request.Name, Surname = "Unknown"};
}
}
如果我这样称呼服务: [http://localhost:24365/users/1?format=json][1]
我收到错误:
{
"ResponseStatus": {
"ErrorCode": "ArgumentException",
"Message": "Could not find property Id on User",
"StackTrace": " konum: ServiceStack.Host.RestPath.CreateRequest(String pathInfo, Dictionary`2 queryStringAndFormData, Object fromInstance)\r\n konum: ServiceStack.Host.RestHandler.CreateRequest(IRequest httpReq, IRestPath restPath, Dictionary`2 requestParams, Object requestDto)\r\n konum: ServiceStack.Host.RestHandler.CreateRequest(IRequest httpReq, IRestPath restPath, Dictionary`2 requestParams)\r\n konum: ServiceStack.Host.RestHandler.CreateRequest(IRequest httpReq, IRestPath restPath)\r\n konum: ServiceStack.Host.RestHandler.ProcessRequestAsync(IRequest httpReq, IResponse httpRes, String operationName)"
}
}
但我在“用户”模型中有“Id”属性。有没有人有这样的问题?
答案 0 :(得分:2)
我在github(line:425)上检查了github是否存在此错误。
我认为行:417会导致此错误。
if (!this.propertyNamesMap.TryGetValue(variableName.ToLower(), out propertyNameOnRequest))
因为“我”和“我”不是我们的电脑语言的相同字符。 (文化:tr-TR)
为了解决问题,我必须在apphost.cs文件中添加一些代码,如下所示:
public class AppHost : AppHostBase
{
public override RouteAttribute[] GetRouteAttributes(Type requestType)
{
var routes = base.GetRouteAttributes(requestType);
routes.Each(x => x.Path = x.Path.ToLower(CultureInfo.GetCultureInfo("en-US")));
return routes;
}
}