Could not load file or assembly Microsoft.IdentityModel.Tokens (related to _FunctionsSkipCleanOutput)
See original GitHub issueA newly-created Azure Functions project fails to load Microsoft.IdentityModel.Tokens
even when the .csproj file contains a PackageReference
to the Microsoft.IdentityModel.Tokens
NuGet package.
Investigative information
N/A, this issue is reproducible locally.
Repro steps
- Clone my repo: https://github.com/srmagura/FunctionsAssemblyLoadingRepro
- Open the solution file in Visual Studio 2022.
- Run the project.
- Go to http://localhost:7071/api/Function1 in your web browser.
Expected behavior
There should be no errors in the debug window. The browser should display the text “Function executed.”
Actual behavior
An error message is displayed in the debug window:
System.Private.CoreLib: Exception while executing function: Function1. FunctionsAssemblyLoadingRepro: Could not load file or assembly 'Microsoft.IdentityModel.Tokens, Version=6.14.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
Known workarounds
Add <_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
to the .csproj file. This is a workaround, not a solution, because this property is internal and undocumented.
Related issues
Issue Analytics
- State:
- Created 2 years ago
- Reactions:9
- Comments:58 (15 by maintainers)
Top Results From Across the Web
Azure function: Could not load file or assembly Microsoft. ...
I got this issue and it seems to be related to some kind of bug in the Azure function ... You can uninstall...
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 >Azure Functions How to fix Could not load file or assembly ...
I am making an Azure Durable Functions application that uses Microsoft. IdentityModel. Tokens.
Read more >Authenticating Azure AD Function fails with "Could not load ...
Hi Siegried, It looks like you are facing an issue with loading the System.IdentityModel.Tokens.Jwt assembly in your compiled C# Azure Function.
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 >
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
Commenting to keep issue open
Also ran into this trying to reference the latest
Microsoft.IdentityModel.JsonWebTokens
library at version6.15.0
It can be repro’d by creating a new azure functions project in vs code using the azure functions extension. Select dotnet 6.0 (in-process) and runtime host of v4. If I try and reference any objects from that library I get the dreadedCould not load file or assembly
error. I did quite the bit of research. Most roads point to the saga that is #5894, and the_FunctionsSkipCleanOutput
suggestion there DID work.However - as others have said - it is a bit of a club. The whole all or nothing approach to cleaning the output. I took a look at the
FunctionsPreservedDependencies
feature that was added in pull 6849 in order to address this defeciency, and it didn’t work for me.Lastly, I did notice that if I pin my
Microsoft.IdentityModel.JsonWebTokens
version to6.10.0
everything worked just fine. 🎉Full example Azure functions csproj below
Sharing this pin to
6.10.0
solution for other folks that don’t may not want to use_FunctionsSkipCleanOutput
orFunctionsPreservedDependencies
. My guess is this works because the azure functions host is currently using this version? Can see it listed in this repo here. Sure would be nice to be able to reference the latest 6.15.0Microsoft.IdentityModel.JsonWebTokens
and it’s security enhancements.Burned a day researching this. Looks like @anthonychu has got feature request 6650 that might help folks save some research time on this?