TypeLoadException when trying to load QueryCollection in .NET 5/.NET 6 isolated function if Microsoft.AspNetCore.Authentication.JwtBearer is referenced
See original GitHub issueVersions 0.9.0-preview and 1.0.0 of Microsoft.Azure.Functions.Worker.Extensions.OpenApi introduced an issue into .NET5/.NET6 isolated functions which reference Microsoft.AspNetCore.Authentication.JwtBearer (5.0.11) when trying to render swagger UI:
[2021-10-22T15:15:40.622Z] System.Private.CoreLib: Exception while executing function: Functions.RenderSwaggerUI. System.Private.CoreLib: Result: Failure
Exception: System.AggregateException: One or more errors occurred. (Could not load type 'Microsoft.AspNetCore.Http.Internal.QueryCollection' from assembly 'Microsoft.AspNetCore.Http, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
)
[2021-10-22T15:15:40.624Z] ---> System.TypeLoadException: Could not load type 'Microsoft.AspNetCore.Http.Internal.QueryCollection' from assembly 'Microsoft.AspNetCore.Http, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
[2021-10-22T15:15:40.626Z] at Microsoft.Azure.Functions.Worker.Extensions.OpenApi.Extensions.OpenApiHttpRequestDataExtensions.Queries(HttpRequestData req)
[2021-10-22T15:15:40.627Z] at Microsoft.Azure.Functions.Worker.Extensions.OpenApi.HttpRequestObject..ctor(HttpRequestData req)
[2021-10-22T15:15:40.630Z] at Microsoft.Azure.Functions.Worker.Extensions.OpenApi.Functions.OpenApiTriggerFunction.RenderSwaggerUI(HttpRequestData req, FunctionContext ctx)
[2021-10-22T15:15:40.631Z] at Microsoft.Azure.Functions.Worker.Extensions.OpenApi.DefaultOpenApiHttpTrigger.RenderSwaggerUI(HttpRequestData req, FunctionContext ctx)
The issue manifests itself the moment Microsoft.AspNetCore.Authentication.JwtBearer is referenced and goes away when the reference is removed.
Version 0.8.1-preview does not exhibit the problem.
Looks like a problem might be with the fact that QueryCollection definition is located in Microsoft.AspNetCore.Http.Internal namespace in .NET Standard 2.0 implementation and in Microsoft.AspNetCore.Http namespace in .NET 5. Possibly introduction of Microsoft.AspNetCore.Authentication.JwtBearer package brings along .NET 5 explicit dependency to Microsoft.AspNetCore.Http.dll
Minimum replication project is attached. QueryCollectionIssueReproduction.zip
I can now confirm that version 1.0.0 still exhibits this issue. Furthermore, both .NET 5 and .NET 6 are affected.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:13 (5 by maintainers)
Top GitHub Comments
@justinyoo Hi Justin, @AieatAssam provided a fix for this 25 days ago. It would be great if the PR could be reviewed and approved please 😃.
@justinyoo I have an open PR #318 that resolves this with minimal changes. Any chance this can be reviewed? We are still unable to upgrade because of this issue.