Created a new Function App, HTTP trigger in VS2019 (16.8.3) to connect to Azure Cache for Redis. Added StackExchange.Redis 2.2.4 from nuget.
local.settings.json contains the key/value of RedisConnectionFromKeyVault and the Primary Connection String from Access keys from the portal.
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"RedisConnectionFromKeyVault": "<<SNIP>>.redis.cache.windows.net:6380,password=<<SNIP>>,ssl=True,abortConnect=False"
}
}
Added the following lines to the default function code:
var connectionRedis = Environment.GetEnvironmentVariable("RedisConnectionFromKeyVault", EnvironmentVariableTarget.Process);
var cache = ConnectionMultiplexer.Connect(connectionRedis).GetDatabase();
When I run and trigger the function app locally I get the following exception on the ConnectionMultiplexer.Connect call.
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:GitReposFunctionApp1FunctionApp1Function1.cs:line 26
Tried similar code in a console app and it works fine?
What am I missing? Why does the function app think it cannot find the System.IO.Pipelines assembly?
Even if I include the System.IO.Piplelines nuget package explicitly it does not find it?
2
Answers
Looks like this is a known issue with Azure Functions as noted at https://github.com/Azure/azure-functions-host/issues/5894
Issues were raised with StackExchange.Redis https://github.com/StackExchange/StackExchange.Redis/issues/1637
https://github.com/StackExchange/StackExchange.Redis/issues/1655
Issue can be resolved by adding the _FunctionsSkipCleanOutput element as below to the csproj
OK I found how to workaround this.
I was referring to the package StackExchange.Redis 2.2.4 (which was making Azure wanting to load System.IO.Pipelines 5.x).
I replaced that package with Microsoft.Extensions.Caching.StackExchangeRedis 5.0.1 (which in turn references StackExchange.Redis 2.0.593 which references System.IO.Pipeline 4.5.2).
Now my functions are working correctly.
Not sure if this is a long term solution though.
Thanks.