2
votes

I'm building a simple web hook function that does some work against Azure Resources using the C# Resource Manager API. The build fails with:

.nuget\packages\microsoft.net.sdk.functions\1.0.2\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(31,5): error : Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.

I've checked and everything is pulling Newtonsoft.Json 9.0.1. I'm guessing it's due to some mismatch in my Nuget packages but not sure how to dig in?

I have:

  • Microsoft.Azure.Management.ResourceManager 1.6.0-preview
  • Microsoft.NET.Sdk.Functions 1.0.2
  • Microsoft.Rest.ClientRuntime.Azure.Authentication 2.3.1

using System.Collections.Generic;  
using System.Net;  
using Newtonsoft.Json;  
using System.Net.Http;  
using System.Threading.Tasks;  
using Microsoft.Azure.Management.ResourceManager;  
using Microsoft.Azure.Management.ResourceManager.Models;  
using Microsoft.Azure.WebJobs;  
using Microsoft.Azure.WebJobs.Host;  
using Newtonsoft.Json.Linq;  
using Microsoft.Rest.Azure.Authentication;    

Using VS2017 15.3.3

1
Do you have a try to install higher version of Newtonsoft.Json and downgrade to version Newtonsoft.Json 9.0.1? We also could get the Microsoft.NET.Sdk.Functions.Build.targets file from the path C:\Users\username\.nuget\packages\microsoft.net.sdk.functions\1.0.2\build\netstandard1.0. Then we could get more info about that. - Tom Sun - MSFT
Have you looked at the file "packages.config" to verify that there isn't a reference to the older version? Also have a look at your "packages" directory under your root project folder and see if any old versions exist there. You could also look at your references in your project: right click Newtonsoft.Json and check the version there to verify it's not the old one. - Architekt

1 Answers

0
votes

It all came down to the preview Resource Manager package.

  • Microsoft.Azure.Management.ResourceManager 1.6.0-preview

Since this is Open Source I went to the GitHub project and checked it out. Essentially came down to it requiring a specific version of NewtonSoft. I fixed my problem by placing the code using the resource manager API into one assembly and just used that. This now works fine in Azure Functions.
In short, look at the dependencies, isolate them in an assembly then include that in your project.