applejag / Newtonsoft.Json-for-Unity

Newtonsoft.Json (Json.NET) 10.0.3, 11.0.2, 12.0.3, & 13.0.1 for Unity IL2CPP builds, available via Unity Package Manager
https://github.com/jilleJr/Newtonsoft.Json-for-Unity
MIT License
1.15k stars 128 forks source link

Bug: Nullable context in Json.NET 12.0.3 crashes testing inside Unity #37

Closed applejag closed 4 years ago

applejag commented 4 years ago

Description

Newtonsoft.Json 12.0.3 introduced usage of the nullable context. It works fine when building the package thanks to the Microsoft.Net.Compilers.Toolset NuGet package that can compile to .NET Framework even if the code contains nullable references syntax.

Less so lucky with Mono inside Unity.

Expected behavior

Mono compiles the Newtonsoft.Json.Tests code to then let Unity Test Framework run all the NUnit tests.

Actual behavior

Syntax error.

Assets/Newtonsoft.Json.Tests/Linq/JTokenTests.cs(371,53): error CS1003: Syntax error, ',' expected
Assets/Newtonsoft.Json.Tests/Linq/JTokenTests.cs(390,36): error CS1525: Invalid expression term 'byte'
Assets/Newtonsoft.Json.Tests/Linq/JTokenTests.cs(390,41): error CS0443: Syntax error; value expected
Assets/Newtonsoft.Json.Tests/Linq/JTokenTests.cs(390,43): error CS1525: Invalid expression term ')'
Assets/Newtonsoft.Json.Tests/Linq/JTokenTests.cs(390,43): error CS1003: Syntax error, ':' expected
Assets/Newtonsoft.Json.Tests/Linq/JTokenTests.cs(408,19): error CS1001: Identifier expected
Assets/Newtonsoft.Json.Tests/Linq/JTokenTests.cs(408,19): error CS1003: Syntax error, ',' expected
Assets/Newtonsoft.Json.Tests/Linq/JTokenTests.cs(408,21): error CS1002: ; expected
Assets/Newtonsoft.Json.Tests/Linq/JTokenTests.cs(417,24): error CS1525: Invalid expression term 'byte'
Assets/Newtonsoft.Json.Tests/Linq/JTokenTests.cs(417,29): error CS0443: Syntax error; value expected
Assets/Newtonsoft.Json.Tests/Linq/JTokenTests.cs(417,31): error CS1525: Invalid expression term ')'
Assets/Newtonsoft.Json.Tests/Linq/JTokenTests.cs(417,31): error CS1003: Syntax error, ':' expected
Assets/Newtonsoft.Json.Tests/Linq/JTokenTests.cs(417,32): error CS1002: ; expected
Assets/Newtonsoft.Json.Tests/Linq/JTokenTests.cs(421,2): error CS1024: Preprocessor directive expected
Assets/Newtonsoft.Json.Tests/Linq/JTokenTests.cs(541,2): error CS1024: Preprocessor directive expected
Assets/Newtonsoft.Json.Tests/Linq/JTokenTests.cs(608,2): error CS1024: Preprocessor directive expected
-----CompilerOutput:-stderr----------
-----EndCompilerOutput---------------

Full logs: https://app.circleci.com/jobs/github/jilleJr/Newtonsoft.Json-for-Unity/468

Details

Host machine OS running Unity Editor ๐Ÿ‘‰ Linux

Unity build target ๐Ÿ‘‰ Linux (Mono)

Newtonsoft.Json-for-Unity package version ๐Ÿ‘‰ 12.0.301

I was using Unity version ๐Ÿ‘‰ 2019.2.11f1, 2018.4.14f1

applejag commented 4 years ago

Turns out referencing the correct NUnit.Framework version (3.5.0.0) in the Newtonsoft.Json.Tests then it can be build by the side and then Unity will see the tests from within the precompiled dll and they're fully runnable.

For reference, found the correct NUnit version by inspecting the Library/PackageCache/com.unity.ext.nunit@1.0.0/net35/unity-custom/nunit.framework.dll, from within the Unity project.

Tested in Unity 2019.2.11f1.

image

For reasons I do not know, there are 5 tests that did not run. Unity won't show which they are. Shows 0 tests if I filter to only show tests that did not run. Weird /shrug

applejag commented 4 years ago

Fixed by #36