system.InvalidCastException: Unable to cast object of type 'Microsoft.AspNetCore.Routing.Patterns.RoutePatternParameterPart' to type 'Microsoft.AspNetCore.Routing.Patterns.RoutePatternLiteralPart'.
See original GitHub issueError reporting using apiversion
[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/[controller]")]
[ApiController]
public class SubscriptionEventsController : SaaSControllerBase
{
private readonly ILogger _logger;
public SubscriptionEventsController(ILogger<ServiceInvocationController> logger)
{
_logger = logger;
}
[Topic(DaprDefaults.BusDefaults.DAPR_PUBSUB_NAME, nameof(DaprDemo_TestEvent))]
[HttpPost("subscription")]
public void Subscription(DaprDemo_TestEvent demoEvent)
{
_logger.LogInformation("Subscription===>{@demoEvent}", demoEvent);
}
}
access /dapr/subscrib
error:
An unhandled exception has occurred while executing the request.
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)
at System.Linq.Enumerable.SelectArrayIterator`2.MoveNext()
at System.String.Join(String separator, IEnumerable`1 values)
at Microsoft.AspNetCore.Builder.DaprEndpointRouteBuilderExtensions.RoutePatternToString(RoutePattern routePattern)
at Microsoft.AspNetCore.Builder.DaprEndpointRouteBuilderExtensions.<>c.<CreateSubscribeEndPoint>b__2_11(ValueTuple`6 e)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.ToList()
at Microsoft.AspNetCore.Builder.DaprEndpointRouteBuilderExtensions.<>c__DisplayClass2_0.<CreateSubscribeEndPoint>b__5(IOrderedEnumerable`1 e)
at System.Linq.Utilities.<>c__DisplayClass2_0`3.<CombineSelectors>b__0(TSource x)
at System.Linq.Enumerable.SelectEnumerableIterator`2.ToArray()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.OrderedEnumerable`1.GetEnumerator()+MoveNext()
at System.Text.Json.Serialization.Converters.IEnumerableOfTConverter`2.OnWriteResume(Utf8JsonWriter writer, TCollection value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.Serialization.Converters.IEnumerableDefaultConverter`2.OnTryWrite(Utf8JsonWriter writer, TCollection value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.Serialization.JsonConverter`1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.Serialization.JsonConverter`1.WriteCore(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.JsonSerializer.WriteCore[TValue](JsonConverter jsonConverter, Utf8JsonWriter writer, TValue& value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.JsonSerializer.WriteCore[TValue](Utf8JsonWriter writer, TValue& value, Type inputType, JsonSerializerOptions options)
at System.Text.Json.JsonSerializer.Serialize[TValue](TValue& value, Type inputType, JsonSerializerOptions options)
at System.Text.Json.JsonSerializer.Serialize[TValue](TValue value, JsonSerializerOptions options)
at Microsoft.AspNetCore.Builder.DaprEndpointRouteBuilderExtensions.<>c.<<CreateSubscribeEndPoint>b__2_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
Unable to cast object of type 'Microsoft.Asp.NetCore.Http. ...
In the application I upload an file (image) to the azure blob storage, and the URL of the uploaded file is stored in...
Read more >System.InvalidCastException: Unable to cast object of type ...
HI, I received this message : System.InvalidCastException: Unable to cast object of type 'System.Int64' to type 'System.Int32'.
Read more >ASP.NET Core 中遇到了dapr subscribe 路由问题_已解决
InvalidCastException : Unable to cast object of type 'Microsoft.AspNetCore.Routing.Patterns.RoutePatternParameterPart' to type 'Microsoft.
Read more >Converting integration tests to .NET Core 3.0
InvalidOperationException : Unable to resolve service for type 'Microsoft.AspNetCore.Hosting.Server.IServer' while attempting to activate ' ...
Read more >How can I fix the 'InvalidCastException: Unable to cast object ...
Coding example for the question How can I fix the 'InvalidCastException: Unable to cast object of type 'System.Int32' to type 'System.String'
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hello,
we have also encountered this problem. We would like to have the ability to define multiple api versions within a controller and also map them to the pub sub model of dapr.
As far as I understand the ASP.net implementation, I can do the following:
I have defined two versions within the controller and mapped the two actions to a specific version each.
I would now expect the Dapr Topic subscription to use the version defined using
MapToApiVersion
(or, if only oneApiVersion
is defined, use the only existing one).Right now, DaprEndpointRouteBuilderExtensions:201 is trying to turn the path segment into a
RoutePatternLiteralPart
, but if we are working with variables within the path, it could also be aRoutePatternParameterPart
.Is there a plan to support these parameters in the near future?
@itsoli91
Currently, only the first route is selected for multiple routes on the SDK
The version of the topic is independent of the SDK. In addition, you can refer to the cloud event version #868 route-messages