简体   繁体   English

Servicestack路由问题,显示“找不到属性”错误

[英]Servicestack routing issue with 'Could not find property' error

When I upgreade the servicestack version of my application to "4.5.12", i am getting error as decribed below. 当我将应用程序的服务堆栈版本升级到“ 4.5.12”时,出现如下所述的错误。

First of all my application configuration is something like this basicly: 首先,我的应用程序配置基本上是这样的:

[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"};
    }
}

If i call service like this: [ http://localhost:24365/users/1?format=json][1] 如果我这样拨打服务电话:[ http:// localhost:24365 / users / 1?format = json] [1]

I am getting error: 我收到错误消息:

{
"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)"
}

} }

But i have "Id" property in "User" model. 但是我在“用户”模型中具有“ Id”属性。 Is there anyone have a problem like this? 有没有人有这样的问题?

I checked github for reason of this error on github(line:425) . 我在github(line:425)上由于这个错误的原因检查了github。

I think line:417 causes this error. 我认为line:417会导致此错误。

if (!this.propertyNamesMap.TryGetValue(variableName.ToLower(), out propertyNameOnRequest))

Because "I" and "i" not same character for our pc language. 因为对于我们的PC语言,“ I”和“ i”不是相同的字符。 (Culture: tr-TR) (文化:tr-TR)

For fixing problem i have to add some codes to apphost.cs file like this: 为了解决问题,我必须向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;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM