Sanjay Singh
Sanjay Singh

Reputation: 714

Azure Functions - Could not load file or assembly ''Microsoft.WindowsAzure.Storage'

I have an azure function that is throwing following error even after i have the dependencies specified in project.json file.

"Could not load file or assembly 'Microsoft.WindowsAzure.Storage, Version=8.1.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified."

{
  "frameworks": {
    "net46": {
      "dependencies": {
        "WindowsAzure.Storage": "8.1.1"
      }
    }
  }
}

I have tried to restart the app service, creating another FunctionApp to rule out any issue with host not loading the updated assemblies, still i cannot get it to work.

Nuget restore also shows that this assembly is being restored but still it keeps giving this error. What else can be wrong and how to go about debugging this issue?

Upvotes: 10

Views: 13566

Answers (5)

Andrei Kniazev
Andrei Kniazev

Reputation: 309

We had a similar issue with our internal NuGet package. The problem was that it was built for x64 architecture only and by default, the Azure Function is created using x32.

So the fix was to compile the NuGet for x32 & x64 or if you cannot do it, try to change the Azure Function platform to 64bit

Upvotes: 0

logeshpalani31
logeshpalani31

Reputation: 1620

I just uninstalled the .NET 6 and Azure Functions Core Tools, then installed .NET 6 SDK and Function Core Tools, the issue resolved automatically enter image description here

Resolved enter image description here

Upvotes: 0

SliverNinja - MSFT
SliverNinja - MSFT

Reputation: 31641

You can use WindowsAzure.Storage 8.1.1 in an Azure Function, you need to put it into the bin/ directory of the Azure Function where your custom assembly resides (Shared Assemblies Strategy). Any assemblies located in the bin/ are probed & loaded first before nuget dependencies / packages are accounted for.

Just use the Azure Function Portal, AppService Editor, Kudu, or FTP to move Microsoft.WindowsAzure.Storage.dll into the /bin.

In my experience, Azure Functions Runtime dependencies will take precedent over any project.json targets. The automatic nuget restore into /data/Functions/packages/nuget will not allow you to use your targeted assemblies once the Azure Function Runtime has loaded them into the AppDomain.

Upvotes: 4

Sanjay Singh
Sanjay Singh

Reputation: 714

It turned out to be a version mismatch issue. Currently, the version of WindowsAzure.Storage package available with AzureFunctions is 7.2.1. I had a custom assembly that had dependencies on 8.1.1 and that is why i was trying to install that using project.json.

Apparently it cannot be done. I switched to 7.2.1 and then it worked just fine. This is always going to be in issue if you are writing precompiled functions because the dependencies should match what is available out of the box with Azure Functions. I hope Microsoft improves this experience in future revisions.

Upvotes: 14

Mikhail Shilkov
Mikhail Shilkov

Reputation: 35134

WindowsAzure.Storage is automatically referenced for you by the environment, so you should not do that manually.

Clean your project.json and just use the assembly from your function's script:

#r "Microsoft.WindowsAzure.Storage"

By referencing NuGet package explicitly, you might be getting version conflict.

See "Referencing External Assemblies" section here.

Upvotes: 9

Related Questions