Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 340
Sanjay Singh Avatar asked Mar 06 '17 05:03

Sanjay Singh


3 Answers

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.

like image 77
Sanjay Singh Avatar answered Nov 12 '22 02:11

Sanjay Singh


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.

like image 43
Mikhail Shilkov Avatar answered Nov 12 '22 03:11

Mikhail Shilkov


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.

like image 3
SliverNinja - MSFT Avatar answered Nov 12 '22 02:11

SliverNinja - MSFT