Connection error when using in Azure Functions

Category: azure cache

Question

vinodkumar4 on Thu, 09 Jan 2020 11:49:51


I am getting following exceptions while using Azure Redis cache in my Azure Functions App. Please help if anyone having idea for this issue.

System.AggregateException
  HResult=0x80131500
  Message=One or more errors occurred. (Could not load file or assembly 'System.Memory, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.)
  Source=System.Private.CoreLib
  StackTrace:
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at StackExchange.Redis.ConnectionMultiplexer.ConnectImpl(Object configuration, TextWriter log) in C:\projects\stackexchange-redis\src\StackExchange.Redis\ConnectionMultiplexer.cs:line 948
   at StackExchange.Redis.ConnectionMultiplexer.Connect(String configuration, TextWriter log) in C:\projects\stackexchange-redis\src\StackExchange.Redis\ConnectionMultiplexer.cs:line 922
   at PerformanceTestLibrary.RedisConnector.<>c__DisplayClass0_0.<.ctor>b__0() in F:\Wenco\POCS\GeoFancing\PerformanceTestLibraryCore\Services\RedisConnector.cs:line 14
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)

  This exception was originally thrown at this call stack:
System.Runtime.Loader.AssemblyLoadContext.ResolveUsingEvent(System.Reflection.AssemblyName)
System.Runtime.Loader.AssemblyLoadContext.ResolveUsingResolvingEvent(System.IntPtr, System.Reflection.AssemblyName)

Inner Exception 1:
FileNotFoundException: Could not load file or assembly 'System.Memory, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

Inner Exception 2:
FileNotFoundException: Could not load the specified file.

Replies

Mike Ubezzi (Azure) on Thu, 09 Jan 2020 21:12:11


Did you build your solution in Visual Studio or did you build your solution in the Azure Portal? It looks like you are missing an assembly but wanted to check to see how you setup/deployed your solution.

Thank you,

Mike

vinodkumar4 on Fri, 10 Jan 2020 05:59:22


Thanks Mike for your reply. I am using Visual Studio to build my solution. By looking at exception, it seems that we are missing an assembly but the same code is working in console app and not working in Functions... its really strange and hard to find out the exact cause of issue. 

Thanks,

Vinod

vinodkumar4 on Fri, 10 Jan 2020 09:20:21


I just noticed that, if I create a seperate class library and reference it in my FunctionApp project, I am getting error which creating connection with Redis in class library and accessing it in my function. When I created the Redis connection in the same function project it worked well. is there any specific reason for this? Please help

Mike Ubezzi (Azure) on Fri, 10 Jan 2020 19:35:32


Can you detail the runtime version of Azure Functions you are targeting and the .NET version?

Azure Functions runtime versions overview

The following GitHub issue details a similar issue: .NET Core: Could not load file or assembly 'System.Runtime, Version=4.2.0.0"

If you are following everything as documented, and you have an Azure Support Plan, please open a Support Request. If you do not have an Azure support plan, please send me your Azure Subscription GUID, and I can have a one-time support request created to have this issue investigated.

Regards,

Mike

supox on Mon, 20 Jan 2020 15:52:55


I was having a similar issue and noticed the same behavior between locally running ok and when I deploy seeing this System.Memory error when accessing redis. In my case we are running on .net core 3.1 and in the csproj file had <AzureFunctionsVersion>v3</AzureFunctionsVersion> but the portal was targeting ~2 using the FUNCTIONS_EXTENSION_VERSION setting in our settings json file. Changing the version in the csproj file to v2 began to mimic the behavior seen deployed version.

The fix in our case to change our settings json file on deploy to make it use ~3 since that was the intention when we upgraded to .net core 3.1

Mike Ubezzi (Azure) on Tue, 21 Jan 2020 00:43:50


Thank you for the update Supox. I am going to propose that as the answer and if the original poster of this thread finds that changing the specific version (as per the runtime version doc based upon SDK) resolves the issue, please mark as answered. If there was a specific detail that can be shared, please share that as well. It helps others facing the same issue and looking for a resolution.

Regards,

Mike

sandeepjaince on Wed, 05 Feb 2020 20:07:05


We are also facing the same issue.  Changing the Azure Runtime from v2 to v3 is not a solution as we have other dependencies which will break. We are facing the issue on local as well as azure environment.

NavtejSaini-MSFT on Fri, 07 Feb 2020 20:28:15


Hi 

These are always intermittent issues which happen cause of the upgrade issues. Here are some of the issues linked to such updates.

Links concerning Azure Updates:

https://azure.github.io/AppService/2018/01/18/Demystifying-the-magic-behind-App-Service-OS-updates.html

https://github.com/Azure/app-service-announcements/issues

https://github.com/Azure/app-service-announcements/issues/139

Hope this helps.

Thanks

Navtej S