Reputation: 125
When I upgreade the servicestack version of my application to "4.5.12", i am getting error as decribed below.
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]
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. Is there anyone have a problem like this?
Upvotes: 1
Views: 284
Reputation: 125
I checked github for reason of this error on github(line:425).
I think line:417 causes this error.
if (!this.propertyNamesMap.TryGetValue(variableName.ToLower(), out propertyNameOnRequest))
Because "I" and "i" not same character for our pc language. (Culture: tr-TR)
For fixing problem i have to add some codes to apphost.cs file like this:
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;
}
}
Upvotes: 2