-
Hello! :). I get this error "System.ArgumentException: Member 'System.Void System.Runtime.CompilerServices.NullableAttribute::.ctor(System.Byte)' " during compilation. Expected behaviorTo compile without an error; Actual behaviorCrash during compilation Steps to reproduce
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour {
// Start is called before the first frame update
void Start() {
JObject item = new JObject();
item["oneKey"] = JObject.FromObject(new RandomItem {anyValue = 1});
string indentedItem = item.ToString(Formatting.Indented);
Debug.Log(indentedItem);
}
}
public class RandomItem {
public int anyValue;
}
DetailsHost machine OS running Unity Editor: Windows Unity build target Windows/WebGL build as High Newtonsoft.Json-for-Unity package version 12.0.301 I was using Unity version 2019.3.12f1 Checklist
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi @SwingWren, interesting scenario you've found where as you say it doesn't even compile. I've sadly not done too much testing with High Stripping Level, but I'll investigate this and hopefully we can come to a solution ASAP! :) |
Beta Was this translation helpful? Give feedback.
-
I love this issue ❤ because the error roots so far down in the IL, and I rarely get to analyse that deep. What's going on is that since Json .NET 12.0.3 it actually includes the NullableAttribute and NullableContextAttribute for C# 8's nullable ref types. The High stripping level for some reason removes the That IL declaration is the equivalent to the following C# code: public void set_Item(string propertyName, [Nullable((byte)2)] JToken value) {} WorkaroundThis is what you actually asked for. Adding the It seems like it's only necessary to specify the <linker>
<assembly fullname="Newtonsoft.Json">
<type fullname="System.Runtime.CompilerServices.NullableAttribute"/>
<type fullname="System.Runtime.CompilerServices.NullableContextAttribute"/>
</assembly>
</linker> And yes, it's supposed to be embedded in the Newtonsoft.Json assembly. Long-term fixI'll probably just write a small thread on the Unity forums, hoping some Unity dev will see it and can perhaps fix it, as it seems like this is a problem with IL2CPP itself. In the meantime I'll toss in the NullableAttribute into the Closing as resolved. Don't fray in reopening the issue if the problem comes back with some other type. Cheers! |
Beta Was this translation helpful? Give feedback.
I love this issue ❤ because the error roots so far down in the IL, and I rarely get to analyse that deep.
What's going on is that since Json .NET 12.0.3 it actually includes the NullableAttribute and NullableContextAttribute for C# 8's nullable ref types.
The High stripping level for some reason removes the
NullableAttribute:.ctor(byte)
constructor, even though it's clearly referenced in theJObject.set_Item
method (used in theitem["oneKey"] =
line).That IL declaration is the equivalent to the following C# code:
Workaround
This is what you actually asked for. Adding the
NullableAttribute
to yourlink.xml
wil…