简体   繁体   中英

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

I am currently working with a Azure Function created in visual studio. It is a timer function that calls some common code to write to a queue.

Running the code locally does not cause any issues. Runs just fine but when publish it I get the following error:

Could not load file or assembly 'Microsoft.WindowsAzure.Storage, Version=9.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.||System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.WindowsAzure.Storage, Version=9.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. File name: 'Microsoft.WindowsAzure.Storage, Version=9.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' at Esperanto.Core.Function.JobGetterLogic.SendJobsToQue() at JobGetter.TimedJob.Run(TimerInfo myTimer, TraceWriter log)

Here is my webjob code:

public static class TimedJob
{
    [FunctionName("TimedJob")]
    public static void Run([TimerTrigger("0 */1 * * * *")]TimerInfo myTimer, TraceWriter log)
    {
        log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
        try
        {
            var brain = new CoreLogic.Function.JobGetterLogic();
            var result = brain.SendJobsToQue();
        }
        catch (Exception e)
        {
            log.Info(e.Message + "||" + e.ToString());
        }

    }
}

Assuming you are on v1 of Azure Functions runtime (current production version), it uses WindowsAzure.Storage assembly of version 7.2.1 . Since it's the runtime which controls which versions are loaded, your implementation has to comply and use the same version.

To fix the problem, change all your references to WindowsAzure.Storage (including transitive ones) to 7.2.1 .

There's currently nothing like binding redirect supported by Azure Functions.

Mine was because of the Newtonsoft.Json version, but I got that even before publishing while installing the WindowsAzure.Storage package.

It gave me this in the output:

NU1107: Version conflict detected for Newtonsoft.Json. Reference the package directly from the project to resolve this issue.
PMTool.AzureFunctions -> WindowsAzure.Storage 9.1.0 -> Newtonsoft.Json (>= 10.0.2) PMTool.AzureFunctions -> Microsoft.NET.Sdk.Functions 1.0.6 -> Newtonsoft.Json (= 9.0.1).

And then rolled back.

So the Newtonsoft.Json in the Functions SDK is version 9.0.1 but on azure storage it is 10.0.2.

And for sure if published like this it gives this error:

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

Because the didn't get referenced at all.

This might not be your exact issue but it might give you a clue.

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