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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With