Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Function App Could not load System.IO.Pipelines connecting to Redis

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:\GitRepos\FunctionApp1\FunctionApp1\Function1.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?

like image 903
briask Avatar asked Feb 04 '23 14:02

briask


1 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

<PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
    <_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput> <!-- *** this line is new ** -->
</PropertyGroup>
like image 154
briask Avatar answered May 11 '23 16:05

briask