简体   繁体   中英

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?

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.

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 .

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 .

I just uninstalled the .NET 6 and Azure Functions Core Tools, then installed .NET 6 SDK and Function Core Tools, the issue resolved automatically 在此处输入图像描述

Resolved在此处输入图像描述

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM