首页 新闻 赞助 找找看

ASP.NET Core 中遇到了 dapr subscribe 路由问题

0
悬赏园豆:30 [已解决问题] 解决于 2022-08-07 18:41

在一个 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)
dudu的主页 dudu | 高人七级 | 园豆:31298
提问于:2022-08-07 17:35
< >
分享
最佳答案
0

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]")]
dudu | 高人七级 |园豆:31298 | 2022-08-07 18:40

去掉 ApiVersion 遇到了新问题

"An API version is required, but was not specified."

添加 [ApiVersionNeutral] 解决

dudu | 园豆:31298 (高人七级) | 2022-08-07 21:01
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册