6

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?

briask
  • 163
  • 1
  • 10

2 Answers2

5

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>
briask
  • 163
  • 1
  • 10
  • Adding <_functionsskipcleanoutput>true to my function project file didn't work for me. netcoreapp3.1 v3 true and exception which I am getting on console - "Anonymously Hosted DynamicMethods Assembly: Object reference not set to an instance of an object." when I am trying to inject IDistributedCache in contructor. – Rahul Apr 12 '21 at 09:11
2

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.

OlyMars93
  • 21
  • 1
  • This does help. Must be some incompatibility between StackExchange.Redis 2.2.4 and Azure Function? – briask Dec 26 '20 at 15:14
  • it looks like StackExchange.Redis 2.2.3 upgraded dependency for System.IO.Pipelines from 4.7.1 to 5.0.0 which is when it fails. StackExchange.Redis 2.1.58 does not experience this same issue. – briask Dec 29 '20 at 11:42