Build/Test Issues

NCrunch fails to test Newtonsoft's JObject.Parse() in .NET Core 2.1

Started by edouard on 5,637 views

I've found that .NET Core 2.1 class libraries that call Newtonsoft's JSON.NET library to parse a JSON document fail in NCrunch.

Minimal example of a failing case:
public class Class1
    {
        [Test]
        public void Test()
        {
            var doc = JObject.Parse("{}");
        }
    }


I get no coverage at all, and no error message as to why the test failed.

If I expand the test to separate the test from the method under test:
   public class Class1
    {
        public void Example()
        {
            var doc = JObject.Parse("{}");
        }

        [Test]
        public void Test()
        {
            Example();
        }
    }


I get an error on the calling Example() line, but no error or coverage in the Example() method. The error on the calling line is:

System.TypeLoadException
Could not load type 'System.Component.IBindingList' from assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.

This is using NUnit, but MSTest seemed to display the same behavior.

If I create a separate .NET Core 2.1 Console Application that creates Class1 and calls Example(), that works fine when I run it.

Cheers,
Edouard.

Edited

Hi, thanks for sharing this issue.

I've managed to reproduce it exactly as you've described it. This looks to be a compatibility issue between .NET Core 2.1, NCrunch and the latest version of Newtonsoft.Json.

I've noticed that when switching Newtonsoft.Json to v10.0.3, the problem doesn't appear. Perhaps this could be used as a temporary workaround.

I'll need to spend some time investigating this before I can advise further. My gut says that this might not be an easy one to fix. I'll let you know as soon as I have more information.
Awesome - thanks for the quick reply.

ASP.NET Core 2.1 takes a dependency on Newtonsoft.Json v11, so I can't downgrade in the code I found it in originally, but luckily that's just POC work for now - it seemed like a good opportunity to check out the bleeding edge. Not, it turns out, 100% problem free...

Looking forward to whether it can be fixed in the future.

Thanks again.

Edited

Adding a Nuget reference from your test project to System.ComponentModel.TypeConverter will resolve this problem without apparent side-effects.

The problem here is caused by the bindings to packages originating from the NCrunch assemblies (which are built for .NET Core 1.0/2.0). Under .NET Core 2.1, the dependency graph for the core system packages seems to be different. We already have this problem in some cases between netcoreapp1.0 and netcoreapp2.0, so I guess 2.1 has made this a bit worse. I was hoping to resolve this by eventually retiring support for netcorepp1.0, but it seems we'll need a more forward thinking solution to have these scenarios working out of the box. Thanks again for taking the time to report this.
Just tried adding that reference, and my tests are now passing. Thanks-you!
The just released v3.18 includes a proper fix for this issue, so hopefully there shouldn't be any need to add these Nuget to work around the problem anymore.

Post a reply

Log in to reply.