【发布时间】:2021-06-16 21:00:58
【问题描述】:
我已经创建了带有 Http 触发器的 Azure Function App,因为我想使用来自 system.runtime 命名空间的内存缓存来缓存令牌。但是当我运行应用程序时,它会抛出错误" 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."
我已确保在项目中安装了确切的版本。这是csproj文件。
<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>
这是我遇到问题的代码的最低版本。
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("");
}
}
【问题讨论】:
-
以上代码在 4.7.0 版本的 system.runtime.caching nuget 上运行良好。我现在已经降级以使其正常工作。
-
您好,既然您已经找到了解决方法,您能否在下面的区域发布答案以供其他社区参考?
标签: azure asp.net-core .net-core azure-functions memorycache