System.IO.FileLoadException when running function ("Microsoft.IdentityModel.Tokens")
See original GitHub issueInvocation ID: 4a8b83e2-2ad0-4f70-a13b-c41295cf6f17 Timestamp: 2018-02-21T16:25:54.224 Function App version (1.0 or 2.0-beta): 2.0-beta
Repro steps
Create a .net core project that contains the function to run.
Add package reference to project like below:
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="5.2.1" />
Call a method that uses the above package and its dependancies.
Example method
public string CreateJWTToken(ClaimsIdentity identity)
{
string _algorithm = "http://www.w3.org/2001/04/xmldsig-more#hmac-sha256";
string _digest = "http://www.w3.org/2001/04/xmlenc#sha256";
var symmetricKey = Encoding.UTF8.GetBytes("<somekey>");
var securityKey = new SymmetricSecurityKey(symmetricKey);
var credentials = new SigningCredentials(securityKey, _algorithm, _digest);
var tokenDescriptor = new SecurityTokenDescriptor();
tokenDescriptor.Subject = identity;
tokenDescriptor.Issuer = "";
tokenDescriptor.Audience = "";
tokenDescriptor.SigningCredentials = credentials;
var tokenHandler = new JwtSecurityTokenHandler();
var token = tokenHandler.CreateToken(tokenDescriptor);
return tokenHandler.WriteToken(token);
}
Expected behavior
Assembly resolved and jwt token created successfully
Actual behavior
Exception is thrown: System.IO.FileLoadException
Could not load file or assembly ‘Microsoft.IdentityModel.Tokens, Version=5.2.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’. Could not find or load a specific file. (Exception from HRESULT: 0x80131621)
Known workarounds
None
Related information
- This fails both on my local functions host and when running in Azure.
- I have inspected the bin folder in both cases and the assembly exists there right along side my application dll.
- I have tried to recreate in a .net core console app and all work well there.
Provide any related information
- Programming language used C#
Binding
{
"generatedBy": "Microsoft.NET.Sdk.Functions.Generator-1.0.8",
"configurationSource": "attributes",
"bindings": [
{
"type": "httpTrigger",
"route": "Authenticate",
"methods": [
"post"
],
"authLevel": "anonymous",
"name": "request"
}
],
"disabled": false,
"scriptFile": "../bin/MyProject.dll",
"entryPoint": "MyProject.Functions.AuthenticateFunction.Run"
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Azure function: Could not load file or assembly Microsoft. ...
An unhandled exception occurred while processing the request. FileLoadException: Could not load file or assembly 'System.IdentityModel.Tokens.
Read more >Azure Function Could not load file or assembly ...
I implemented an application "Azure Functions" that makes use of "Microsoft.IdentityModel.Protocols.OpenIdConnect" to authenticate the session of a user, ...
Read more >Resolving the "Could Not Load File or Assembly System. ...
A description on how I resolved the "Could not load file or assembly System.IdentityModel.Tokens.Jwt" in an Azure Functions application.
Read more >Azure Functions How to fix Could not load file or assembly ...
Tokens. When this chunk of code runs I am getting the error "Could not load file or assembly 'Microsoft.IdentityModel.Tokens, Version=6.30.
Read more >“Could not load file or assembly 'Microsoft.IdentityModel ...
“Could not load file or assembly 'Microsoft.IdentityModel.JsonWebTokens” when running PowerShell in Azure Functions.
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
I’m running into the same issue with Microsoft.IdentityModel.Tokens Version=“5.2.2”.
As a workaround I downgraded to version 5.1.4 which loads without problems
As mentioned. Work is in progress and fixes will be deployed with the next release. Leaving this open and moving to Sprint 25 for validation