1

I have an Azure Function project with multiple Nuget packages installed. These packages depend on different versions of Newtonsoft, and that's causing problems. I understand from this post (Newtonsoft.json assembly package version mismatch) that the normal solution is to add an assembly-binding configuration (ie: a redirect) to the config file.

How would one accomplish this in an Azure function, which doesn't have a config file?

I added an App.config file to the project, and it now looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.2"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

But I still get the same error:

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

Thanks!

Casey Crookston
  • 13,016
  • 24
  • 107
  • 193
  • 1
    I've faced the same problem in the past and I should advice you that it's a nightmare. My advice to you: move everything to a Container, and host it on Azure Container Instances, where you can have more control over the dependencies. Use Azure Functions just as a trigger that will call the other APIs hosted on ACI. – Thiago Custodio Oct 22 '19 at 19:55
  • @ThiagoCustodio, ok thank you! Good to know. The Azure function is indeed a very thin layer. Most of the logic exists inside business logic classes. I will try and move the logging functionality we are trying to implement out of the thin Azure function and down into the business logic class. – Casey Crookston Oct 22 '19 at 20:00
  • If you can't move to v2, then that's the best way. – Thiago Custodio Oct 22 '19 at 20:09
  • @ThiagoCustodio... v2? – Casey Crookston Oct 22 '19 at 20:12
  • https://learn.microsoft.com/en-us/azure/azure-functions/functions-versions – Thiago Custodio Oct 22 '19 at 20:13
  • ah. core. Yeah, not there. – Casey Crookston Oct 22 '19 at 20:27
  • @ThiagoCustodio, ok, next question/problem. I moved the addition of the nuget packages in question down into the business logic project. In the project, the `dependentAssembly` entry in the app.config for Newtonsoft is already there. Figured I'd be okay. But I get the exact same error. Is this going to be a problem whenever I run it from the context of an Azure (v1) function? – Casey Crookston Oct 22 '19 at 20:31
  • exactly. As you're in v1, the version of Newtonsoft is freezed on 9.3.3 or 10.0.2 can't remember by heart. So, you'll need to downgrade all your packages that needs Newtonsoft to one that uses the version 9.3.3 10.0.2. And this is where the nightmare starts... – Thiago Custodio Oct 22 '19 at 21:14
  • 1
    good lord. Already tried to downgrade Newtonsoft, but that threw another error because another nuwget package depends on the higher version – Casey Crookston Oct 22 '19 at 21:18
  • that what I was talking about... – Thiago Custodio Oct 22 '19 at 21:24

0 Answers0