Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeLoadException when trying to load QueryCollection in .NET 5/.NET 6 isolated function if Microsoft.AspNetCore.Authentication.JwtBearer is referenced

See original GitHub issue

Versions 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=, 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=, 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.

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:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

r0ss88commented, Dec 13, 2021

@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 😃.

AieatAssamcommented, Jan 5, 2022

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Package Microsoft.AspNetCore.Authentication.JwtBearer ...
Net Core 3.1. I keep getting this error message: Package Microsoft.AspNetCore.Authentication.JwtBearer 5.0.0 is not compatible with netcoreapp3.
Read more >
How to proxy requests to the Azure Function?
I'm thinking to use the controller in the Main Project where I have Azure Functions and .NET Core Project in the same local...
Read more >
Microsoft.Identity.Web and Azure Functions - Honza's Blarg
I recently run into an interesting situation with authentication. Since serverless and Azure Functions are gaining more and more traction, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found