在VS2019 (16.8.3)中创建了一个新的函数应用程序,HTTP触发器,以连接到Azure Cache for 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();当我在本地运行并触发函数app时,我在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包,它也找不到它吗?
发布于 2020-12-30 04:00:50
看起来这是https://github.com/Azure/azure-functions-host/issues/5894上提到的Azure函数的一个已知问题
使用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>发布于 2020-12-26 05:25:01
好吧,我找到了解决这个问题的方法。
我指的是Azure 2.2.4包(它使得StackExchange.Redis想要加载System.IO.Pipelines 5.x)。
我将该包替换为Microsoft.Extensions.Caching.StackExchangeRedis 5.0.1 (它又引用了StackExchange.Redis 2.0.593,后者又引用了System.IO.Pipeline 4.5.2)。
现在我的函数可以正常工作了。
不过,我不确定这是否是一个长期的解决方案。
谢谢。
https://stackoverflow.com/questions/65382540
复制相似问题