Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure function: Could not load file or assembly Microsoft.IdentityModel.Tokens, Version=5.2.1.0

Im writing an azure function to generate a JWT token and return it to the client. The code is tested locally in a console app and all seems to work fine. This is the package reference included in the working console app, and in my functions app:

<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.2.1" />

When running the function host locally with func host start and executing the code it results in the error:

Could not load file or assembly 'Microsoft.IdentityModel.Tokens, Version=5.2.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'."

I don't understand why this is happening, the dll is laying in the output folder along with my application dll. The only other thing I can think of is that the function host has its own set of packages that it sources from and this one is not available yet, having been only released 12 days ago.

I'm not sure. Any help on why this is happening or how to get around it?

Details:
Azure Functions Core Tools (2.0.1-beta.22)
Function Runtime Version: 2.0.11415.0

like image 715
Craigt Avatar asked Feb 20 '18 16:02

Craigt


2 Answers

I got this issue and it seems to be related to some kind of bug in the Azure function SDK. the fix was to add:

<_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>

to your csproj file. As documented here

like image 189
Liam Avatar answered Oct 12 '22 15:10

Liam


I had installed this package Microsoft.AspNetCore.Authentication.JwtBearer

And for me, the issue was resolved.

You can uninstall System.IdentityModel.Tokens.Jwt

Because the Microsoft package depends on the system package, so it gets installed automatically.

like image 42
Varun Avatar answered Oct 12 '22 15:10

Varun