2

I have created Azure Function App with Http trigger in that I want to use memory cache from system.runtime namespace to cache the token. but when I run the application its throwing the error " System.Runtime.Caching: Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified."

I have made sure the exact version is installed in the project. here is the csproj file.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.11" />
    <PackageReference Include="System.Configuration.ConfigurationManager" Version="5.0.0" />
    <PackageReference Include="System.Runtime.Caching" Version="5.0.0" />
  </ItemGroup>
  <ItemGroup>

Here is the bare minimum version of the code where I am facing the issue.

public static class Function1
    {
        public static MemoryCache accessTokenCache = new MemoryCache("accessToken");
        [FunctionName("Function1")]
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            accessTokenCache.Add("123", "123", new CacheItemPolicy() { Priority = CacheItemPriority.Default });

            return new OkObjectResult("");
        }
    }
threeleggedrabbit
  • 1,722
  • 2
  • 28
  • 60

1 Answers1

3

above code works fine with system.runtime.caching nuget with version 4.7.0. I have downgraded for now to get it work.

I have also posted the issue in github for further follow up. https://github.com/Azure/Azure-Functions/issues/1867

threeleggedrabbit
  • 1,722
  • 2
  • 28
  • 60