Failed to resolve assembly: 'Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'

684 Views Asked by At

In one of my projects this issue came up when building in release mode. It works fine in debug mode.

My project is a WPF application targetting .NET Framework 4.8.

1

There are 1 best solutions below

0
Luke On

The issue came up due to using a nuget package called ILRepack.Lib.MSBuild.Task.

This nuget package should have bound all external needed *.dll into the *.exe on release config builds.

One solution is to just get rid of ILRepack.

But that did not work for me. So I dug deeper. Finding, that on one class I had something like this:

// The following attribute was the culprit
[JsonObject(MemberSerialization.OptIn)]
internal class MyClass
{   
    [JsonProperty]
    public string Property1 { get; set; }

    public int[] Property2 { get; set; }
}

The class attribute without a parameter did work. But with a parameter (regardless of its value) it caused the problem.

So I just opted for the following:

internal class MyClass
{   
    [JsonProperty]
    public string Property1 { get; set; }
    [JsonIgnore]
    public int[] Property2 { get; set; }
}

This way I had all the features I desired, and got rid of the build issue.