Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assembly binding redirect in Azure Functions

I have created an Azure function and as we know it has the package Microsoft.NET.Sdk.Functions 1.0.8 which is dependent on Newtonsoft.Json 9.0.1.

I have added another class library as a reference to this Azure Function which depends on Newtonsoft.Json 11.0.2.

During runtime, I get an error stating:

"FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified."

This looks like a problem related to Assembly Binding Redirects so I follow this solution to try and fix https://codopia.wordpress.com/2017/07/21/how-to-fix-the-assembly-binding-redirect-problem-in-azure-functions/ But, this doesn't help as well.

Is there a step that I'm missing or any other workaround for this kind of case? Help is appreciated.

like image 553
Hari Krishna Avatar asked May 03 '18 07:05

Hari Krishna


People also ask

What is assembly binding redirect?

Rely on automatic binding redirection This means that if two components reference different versions of the same strong-named assembly, the runtime automatically adds a binding redirection to the newer version of the assembly in the output app configuration (app. config) file.

Can an azure function have multiple output bindings?

Bindings are optional and a function might have one or multiple input and/or output bindings. Triggers and bindings let you avoid hardcoding access to other services. Your function receives data (for example, the content of a queue message) in function parameters.

What is binding in Azure function?

A binding is a connection to data within your function. Bindings are optional and come in the form of input and output bindings. An input binding is the data that your function receives. An output binding is the data that your function sends.

Why does Nuget add binding redirects?

Binding redirects are added if your app or its components reference more than one version of the same assembly, even if you manually specify binding redirects in the configuration file for your app.


1 Answers

Azure functions don't have a notion of binding redirect. If your functions app has a reference to a library that depends on a specific version (say version x) of Newtonsoft.Json and the Microsoft.Net.Sdk.Functions has implicit dependency on another version (say version y), as a workaround you can add explicit reference to version x of Newtonsoft.Json in your functions app by running this on your Package Manager Console.

Install-Package Newtonsoft.Json -Version x

This will make your project dependency show a yellow warning sign but you won't get a runtime error.

enter image description here

like image 136
Hiral Desai Avatar answered Oct 10 '22 02:10

Hiral Desai