domaindrivendev / Swashbuckle.AspNetCore

Swagger tools for documenting API's built on ASP.NET Core
MIT License
5.26k stars 1.32k forks source link

[Bug]: System.InvalidOperationException: TryParse method found on Guid with incorrect format #3117

Open kirillkrylov opened 1 month ago

kirillkrylov commented 1 month ago

Describe the bug

This line causes the error

jobsApi.MapGet("/Status/{id:guid}",JobStatusById);

however this works as expected

jobsApi.MapGet("/Status/{id}",JobStatusById);

image

Expected behavior

Not throw

Actual behavior

Throws exeption

Steps to reproduce

No response

Exception(s) (if any)

Microsoft.AspNetCore.Server.Kestrel[13]
      Connection id "0HN7JJO47LKTO", Request id "0HN7JJO47LKTO:00000002": An unhandled exception was thrown by the application.
      System.InvalidOperationException: TryParse method found on Guid with incorrect format. Must be a static method with format
      bool TryParse(string, IFormatProvider, out Guid)
      bool TryParse(string, out Guid)
      but found
      static Boolean TryParse(System.String, System.IFormatProvider, System.Guid ByRef)
         at Microsoft.AspNetCore.Http.ParameterBindingMethodCache.<FindTryParseMethod>g__Finder|14_0(Type type) + 0x83d
         at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey, Func`2) + 0xa4
         at Microsoft.AspNetCore.Http.ParameterBindingMethodCache.HasTryParseMethod(Type) + 0x26
         at Microsoft.AspNetCore.Mvc.ApiExplorer.EndpointMetadataApiDescriptionProvider.GetBindingSourceAndName(ParameterInfo, RoutePattern, Boolean) + 0x674
         at Microsoft.AspNetCore.Mvc.ApiExplorer.EndpointMetadataApiDescriptionProvider.CreateApiParameterDescription(ParameterInfo, RoutePattern, Boolean) + 0x52
         at Microsoft.AspNetCore.Mvc.ApiExplorer.EndpointMetadataApiDescriptionProvider.CreateApiDescription(RouteEndpoint, String, MethodInfo, Boolean) + 0x290
         at Microsoft.AspNetCore.Mvc.ApiExplorer.EndpointMetadataApiDescriptionProvider.OnProvidersExecuting(ApiDescriptionProviderContext) + 0x322
         at Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescriptionGroupCollectionProvider.GetCollection(ActionDescriptorCollection) + 0x4f
         at Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescriptionGroupCollectionProvider.get_ApiDescriptionGroups() + 0x35
         at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwaggerDocumentWithoutPaths(String, String, String) + 0x76
         at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.<GetSwaggerAsync>d__6.MoveNext() + 0x6f
      --- End of stack trace from previous location ---
         at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x20
         at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xb2
         at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task, ConfigureAwaitOptions) + 0x4b
         at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.<Invoke>d__6.MoveNext() + 0x219
      --- End of stack trace from previous location ---
         at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x20
         at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xb2
         at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task, ConfigureAwaitOptions) + 0x4b
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.<ProcessRequests>d__238`1.MoveNext() + 0x404

Swashbuckle.AspNetCore version

6.9.0

.NET Version

8.0.403

Anything else?

issue reproducible in AOT

martincostello commented 1 month ago

The stack trace suggests this is an issue in ASP.NET Core, rather than Swashbuckle - we're just calling into its API Description layer.

If it is an issue here, then we'll need a minimal reproducible example as a GitHub repository that demonstrates the issue you're experiencing so we can look into this further with the debugger. The example as-given is missing the endpoint method itself, as well as the project configuration (you mention native AoT, for example).