I am making an Azure Durable Functions application that uses Microsoft.IdentityModel.Tokens.
When this chunk of code runs I am getting the error "Could not load file or assembly 'Microsoft.IdentityModel.Tokens, Version=6.30.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified."
private static string GenerateRandomString(int length)
{
var bytes = RandomNumberGenerator.GetBytes(length);
return Base64UrlEncoder.Encode(bytes);
}
I have seen another people having the same issue talking about an automatic system cleaning the package references when publishing. There are multiple suggestions about using the following lines in the .csproj.
<ItemGroup>
<_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
<FunctionsPreservedDependencies Include="Microsoft.AspNetCore.Authentication.JwtBearer"/>
</ItemGroup>
But even after doing it and republishing the issue persists.
At this point I am stuck and cant put my application to work. I dont know what to do, the error seems unfixable and there is no proper documentation regarding this matter.
Here is my complete .csproj just in case anybody needs some extra context.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<RootNamespace>My_Application</RootNamespace>
<DockerFastModeProjectMountDirectory>/home/site/wwwroot</DockerFastModeProjectMountDirectory>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.16" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="2.9.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.OpenApi" Version="1.0.0" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.30.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.1" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.17.2" />
</ItemGroup>
<ItemGroup>
<FunctionsPreservedDependencies Include="Microsoft.AspNetCore.Authentication.JwtBearer"/>
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>