Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

NCrunch fails to test Newtonsoft's JObject.Parse() in .NET Core 2.1
edouard
#1 Posted : Thursday, July 12, 2018 1:29:35 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 7/12/2018(UTC)
Posts: 3
Location: New Zealand

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
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:
Code:
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:
Code:
   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.
Remco
#2 Posted : Thursday, July 12, 2018 6:20:56 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,144

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
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.
edouard
#3 Posted : Thursday, July 12, 2018 7:44:34 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 7/12/2018(UTC)
Posts: 3
Location: New Zealand

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
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.
Remco
#4 Posted : Friday, July 13, 2018 12:23:59 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,144

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
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.
1 user thanked Remco for this useful post.
edouard on 7/13/2018(UTC)
edouard
#5 Posted : Friday, July 13, 2018 1:10:24 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 7/12/2018(UTC)
Posts: 3
Location: New Zealand

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
Just tried adding that reference, and my tests are now passing. Thanks-you!
1 user thanked edouard for this useful post.
Remco on 7/13/2018(UTC)
Remco
#6 Posted : Wednesday, August 1, 2018 8:17:36 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,144

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
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.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.037 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download