在一个 ASP.NET Core 项目中订阅 dapr 消息,在请求 /dapr/subscribe 时出现了下面的错误,请问如何解决?
System.InvalidCastException: Unable to cast object of type 'Microsoft.AspNetCore.Routing.Patterns.RoutePatternParameterPart' to type 'Microsoft.AspNetCore.Routing.Patterns.RoutePatternLiteralPart'.
at System.Linq.Enumerable.CastIterator[TResult](IEnumerable source)+MoveNext()
at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
at System.String.Concat(IEnumerable`1 values)
at Microsoft.AspNetCore.Builder.DaprEndpointRouteBuilderExtensions.<>c.<RoutePatternToString>b__3_0(RoutePatternPathSegment segment)
在 https://github.com/dapr/dotnet-sdk/issues/791 找到了答案,是 dapr .net sdk 不支持 [ApiVersion]
引起的,去掉 ApiVersion 就可以了
Removing or hardcoding the version from the controller route fixes the issue?
[Route("api/v1.0/[controller]")]
去掉 ApiVersion 遇到了新问题
"An API version is required, but was not specified."
添加 [ApiVersionNeutral]
解决