ullmark/hashids.net

HashIds.net does not work in Azure Functions

royalghost opened this issue · 9 comments

When bundled with Azure Functions using dotnetcore3.1, hashids.net does not work in runtime and throws following exception Could not load file or assembly 'Microsoft.Extensions.ObjectPool, Version=5.0.0.0, Culture-neutral ...

What is the workaround to use hashids in Azure Functions ?

That library should work fine with netstandard2.0 which is supported by netcore3.1

Do you have any code you can share? It'll be quicker to debug.

Thanks for reaching out. I have created a new bare minimum Azure Functions at https://github.com/royalghost/HttpTriggerDemo that fails with the following exception :

Executed 'HttpTriggerDemo' (Failed, Id=6decf220-8654-41f1-932d-3d7597391118)
[6/30/2021 10:08:42 PM] System.Private.CoreLib: Exception while executing function: HttpTriggerDemo. Hashids.net: Could not load file or assembly 'Microsoft.Extensions.ObjectPool, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.

However, if I downgrade <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.13" /> to 3.0.3 it does work. Looks like the library is broken for latest release.

Thanks for the info. Looks like it's limited to the Functions library then. There's not much we could really do about this problem since it's built for netstandard2.0 already. Can you work with using that lower version of the functions library?

It seems this commit to to use ObjectPool is causing this exception. Could you take a look at why using Microsoft.Extensions.ObjectPool could be a issue here as I am not in a position to lower the functions library version ?

The library uses ObjectPool to reuse the StringBuilder and save significant allocations. The Microsoft.Extensions.ObjectPool library itself is already multitargeted to include netstandard2.0 and the functions environment doesn't provide much to debug.

It's unlikely that we'll stop using the ObjectPool but I'll see if there's an alternative. Please share if you have any other logs or info to contribute.

hey @royalghost

I replaced the ObjectPool package with a simple internal implementation (PR #45). The new hashids version 1.4.1 is published on nuget: https://www.nuget.org/packages/Hashids.net/1.4.1

Your function code works now: https://appdev2.azurewebsites.net/api/HttpTriggerDemo?

Let me know if that solves it for you.

Thanks @manigandham for publishing a new version with a fix. It seems the change has fixed the issue. I will run few more test cases and close this defect in next few days.

Assuming this solved the problem so closing the issue. Let us know if you find any new problems.

Thanks for closing. Yes, it solved the issue. Really appreciate for your help!