Azure-functions-vs-build-sdk: Could not load file or assembly System.IdentityModel.Tokens.Jwt, Version=5.6.0.0

Created on 6 Mar 2020  路  17Comments  路  Source: Azure/azure-functions-vs-build-sdk

The error occurs when upgrading Microsoft.NET.Sdk.Functions to version 3.0.4 or 5 from 3.0.3

Full error:
Could not load file or assembly 'System.IdentityModel.Tokens.Jwt, Version=5.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.":"System.IdentityModel.Tokens.Jwt, Version=5.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"}

Most helpful comment

@ErikAndreas this worked for me for System.IdentityModel.Tokens.Jwt but note the _ at the begining of functions
<_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>

All 17 comments

Got a similar problem. Upgraded from 3.0.2 to .5 and getting runtime exception:
An unhandled host error has occurred.
Could not load file or assembly 'Microsoft.IdentityModel.Protocols, Version=5.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.

class loaded at runtime (in another project, same solution, if that is of interest) declares (amongst other but prolly related):
using Microsoft.IdentityModel.Protocols;
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
using Microsoft.IdentityModel.Tokens;
using System.IdentityModel.Tokens.Jwt;

adding <FunctionsSkipCleanOutput>true</FunctionsSkipCleanOutput> (child of startup project .csproj PropertyGroup, maybe it should be somewhere else?) has no effect as per suggestion https://twitter.com/codesapien/status/1235999437131898880

@ErikAndreas this worked for me for System.IdentityModel.Tokens.Jwt but note the _ at the begining of functions
<_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>

Hey @BadTactx it did, thanks! (who'd thought actually doing exactly as stated would work... I though the '_' was for escaping on twitter or something...). For reference:
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netcoreapp3.1</TargetFramework> <AzureFunctionsVersion>v3</AzureFunctionsVersion> <_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput> </PropertyGroup>
Does seem to work with 3.0.5

Just to add my experience too, very frustrating error when publishing to Azure but the _FunctionsSkipCleanOutput property (including the underscore prefix!) worked a treat.

I have the same issue here after upgrading from 3.0.3 to 3.0.5. FYI:

  • You can just downgrade to 3.0.3 to fix this.
  • Using _FunctionsSkipCleanOutput indeed also works
  • Publishing to 2 different (empty) folders changing only _FunctionsSkipCleanOutput shows a big difference in amount of assemblies in the output (function.deps.json and extensions.json are identical):

    • value false: 27 assemblies are copied

    • value true: 92 assemblies are copied

      Missing for false include Microsoft.AspNetCore.* , Microsoft.Extensions.* and System.* assemblies. Hence the 'Could not load file or assembly' message after deploy..

Even if downgrade works (and thanks guys for it!!!), this is quite anoying bug - any update on this?

For now, using <_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput> is the right approach to getting around this.

I'm going to close this issue and use https://github.com/Azure/azure-functions-host/issues/5894 to track the fix.

I understand that <_FunctionsSkipCleanOutput> is an undocumented internal prop. But Since we are using it as a workaround now, can someone please explain what does this exactly do ?

I'd also like to know what it does and whether it is safe to keep it checked in to source control because I know I'm going to forget about this soon.

This property is completely safe and will continue to be supported. We added a feature a few months ago (https://github.com/Azure/azure-functions-host/pull/5626) that takes a pre-determined list of assemblies and deletes them from your output directory after a build or publish. These assemblies are already installed on the server so they were deemed unnecessary. This keeps the published package size lower.

But in some cases it doesn't work -- for example if you're trying to use a newer version than is installed on the server. Specifying _FunctionsSkipCleanOutput skips that deleting step and leaves all the assemblies there -- resulting in a bigger package size, but ensuring that all the assemblies you need are deployed with your app. This effectively reverts you back to the same behavior we had for several years.

We've got some work items to make this better -- but don't have a timeline for fixing it yet.

This property is completely safe and will continue to be supported. We added a feature a few months ago (Azure/azure-functions-host#5626) that takes a pre-determined list of assemblies and deletes them from your output directory after a build or publish. These assemblies are already installed on the server so they were deemed unnecessary. This keeps the published package size lower.

But in some cases it doesn't work -- for example if you're trying to use a newer version than is installed on the server. Specifying _FunctionsSkipCleanOutput skips that deleting step and leaves all the assemblies there -- resulting in a bigger package size, but ensuring that all the assemblies you need are deployed with your app. This effectively reverts you back to the same behavior we had for several years.

We've got some work items to make this better -- but don't have a timeline for fixing it yet.

Thank you for the clarity there.

@brettsam Thanks! Looking forward to a better fix. To me, it sounds like the removal process needs to be smart taking into account the customer's assembly versions in comparison to server assembly versions before removing them.

This issue is still alive. It just happened to me with AzureFunction v3 and updating System.IdentityModel.Tokens.Jwt from 6.6.0 to 6.7.1. The fix here did worked.

@ramiglez30 -- to be clear, you were updating your dependency, saw that it failed, then used the property above to fix it?

Yes. I did and it worked. Thanks!

This property is completely safe and will continue to be supported. We added a feature a few months ago (Azure/azure-functions-host#5626) that takes a pre-determined list of assemblies and deletes them from your output directory after a build or publish. These assemblies are already installed on the server so they were deemed unnecessary. This keeps the published package size lower.

But in some cases it doesn't work -- for example if you're trying to use a newer version than is installed on the server. Specifying _FunctionsSkipCleanOutput skips that deleting step and leaves all the assemblies there -- resulting in a bigger package size, but ensuring that all the assemblies you need are deployed with your app. This effectively reverts you back to the same behavior we had for several years.

We've got some work items to make this better -- but don't have a timeline for fixing it yet.

Does this mean anything in terms of performance (execution/ assemblies loaded during runtime) for Azure Functions as the package size is bigger without cleanup being performed? How do we keep ourselves informed about the changes related to this in the future, lets say when you would have a timeline defined? would there be a consideration to upgrade the project file to remove this prop? Because this is a project prop, it makes it very hard to keep track.

However, I have to say, indeed the prop fixes the issues, so one issue taken care of 馃憤

6.9 update from today
Die Datei oder Assembly "Microsoft.IdentityModel.Tokens, Version=5.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" oder eine Abh盲ngigkeit davon wurde nicht gefunden. Die gefundene Manifestdefinition der Assembly stimmt nicht mit dem Assemblyverweis 眉berein. (Ausnahme von HRESULT: 0x80131040)

Was this page helpful?
0 / 5 - 0 ratings