cake-contrib/Cake.Json

Method not found: ParseJsonFromFile

CJJ69 opened this issue · 4 comments

CJJ69 commented

Method not found: 'Newtonsoft.Json.Linq.JObject Cake.Json.JsonAliases.ParseJsonFromFile(Cake.Core.ICakeContext, Cake.Core.IO.FilePath)

Expected Behavior

trying to use latest version of Cake.json 4.0.0

#addin nuget:?package=Cake.Json&version=4.0.0
#addin nuget:?package=Newtonsoft.Json&version=11.0.2

FilePath packageFilePath = new FilePath(rootDirectory.Path.ToString() + @"/package.json");
var json = ParseJsonFromFile(packageFilePath);

expected to read json from file

Current Behavior

Error: One or more errors occurred.
Method not found: 'Newtonsoft.Json.Linq.JObject Cake.Json.JsonAliases.ParseJsonFromFile(Cake.Core.ICakeContext, Cake.Core.IO.FilePath)'.

Possible Solution

Avoid using Cake.json alias - just code around it...

var json = Newtonsoft.Json.Linq.JObject.Parse (System.IO.File.ReadAllText(packageFilePath.FullPath));

Steps to Reproduce (for bugs)

  1. include addins for Cake.json and Newtonsoft.Json
  2. try to read from a json file with alias ParseJsonFromFile

Context

Your Environment

  • Module version used:
    4.0.0
    11.0.2
  • Operating System and PowerShell version:
    Win 10
gep13 commented

@CJJ69 I have just tried the following:

#addin nuget:?package=Cake.Json&version=4.0.0

Task("Default")
  .Does(() =>
{
  FilePath packageFilePath = new FilePath("package.json");
  var json = ParseJsonFromFile(packageFilePath);
  Information(json);
});

RunTarget("Default")

And it works as expected:

image

CJJ69 commented

Hi @gep13

Yes you're right, I can confirm that does work.

Now add in Newtonsoft.Json as per the README...
NOTE: It's very important at this point in time to specify the Newtonsoft.Json package and the version 11.0.2 for it.

#addin nuget:?package=Cake.Json&version=4.0.0
#addin nuget:?package=Newtonsoft.Json&version=11.0.2

This combo of packages fails for me too, but reverting to Newtonsoft.Json version 10.0.3 worked for me, if you're able to.

#addin nuget:?package=Cake.Json&version=4.0.0
#addin nuget:?package=Newtonsoft.Json&version=10.0.3
gep13 commented

@CJJ69 @joshstrohminger I am going to go ahead and close this issue out, as I believe that there is nothing else required to be done here.