Azure Function App 无法加载 System.IO.Pipelines 连接到 Redis

问题描述

在 VS2019 (16.8.3) 中创建了一个新的函数应用程序、HTTP 触发器以连接到 Azure Redis 缓存。从 nuget 添加了 StackExchange.Redis 2.2.4。

local.settings.json 包含 RedisConnectionFromkeyvault 的键/值和来自门户访问键的主连接字符串。

{
    "IsEncrypted": false,"Values": {
    "AzureWebJobsstorage": "UseDevelopmentStorage=true","FUNCTIONS_WORKER_RUNTIME": "dotnet","RedisConnectionFromkeyvault": "<<SNIP>>.redis.cache.windows.net:6380,password=<<SNIP>>,ssl=True,abortConnect=False"
  }
}

函数代码添加了以下几行:

var connectionRedis = Environment.GetEnvironmentvariable("RedisConnectionFromkeyvault",EnvironmentvariableTarget.Process);
var cache = ConnectionMultiplexer.Connect(connectionRedis).GetDatabase();

当我在本地运行并触发函数应用程序时,我在 ConnectionMultiplexer.Connect 调用中遇到以下异常。

System.Private.CoreLib: Exception while executing function: Function1. StackExchange.Redis: Could not load file or assembly 'system.io.pipelines,Version=5.0.0.0,Culture=neutral,PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
   at StackExchange.Redis.ConnectionMultiplexer.Connect(Configurationoptions configuration,TextWriter log) in /_/src/StackExchange.Redis/ConnectionMultiplexer.cs:line 1032
   at StackExchange.Redis.ConnectionMultiplexer.Connect(String configuration,TextWriter log) in /_/src/StackExchange.Redis/ConnectionMultiplexer.cs:line 1015
   at FunctionApp1.Function1.<Run>d__0.MoveNext() in E:\GitRepos\FunctionApp1\FunctionApp1\Function1.cs:line 26

在控制台应用程序中尝试过类似的代码,它工作正常吗?

我错过了什么?为什么函数应用认为找不到 system.io.pipelines 程序集?

即使我明确包含 System.IO.Piplelines nuget 包,它也找不到它?

解决方法

看起来这是 Azure Functions 的一个已知问题,如 https://github.com/Azure/azure-functions-host/issues/5894

所述

StackExchange.Redis 提出了问题 https://github.com/StackExchange/StackExchange.Redis/issues/1637

https://github.com/StackExchange/StackExchange.Redis/issues/1655

问题可以通过将 _FunctionsSkipCleanOutput 元素添加到 csproj 来解决,如下所示

<PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
    <_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput> <!-- *** this line is new ** -->
</PropertyGroup>