• Stars
    star
    915
  • Rank 48,130 (Top 1.0 %)
  • Language
    C#
  • License
    MIT License
  • Created over 8 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Forked Newtonsoft.Json to support Unity3D

Build status

Newtonsoft Json.NET for Unity3D

Newtonsoft Json.NET is a de facto standard JSON library in .NET ecosystem. But it doesn't support Unity3D, so it's a little bit hard to use JSON.NET just after getting Json.NET package. This package is for Unity3D programmers that need to use latest Json.NET in Unity3D.

Where can I get it?

Visit Release page to get latest Json.NET unity-package.

To use this library in IL2CPP build settings, you need to add link.xml to your project's asset folder. For detailed information about link.xml, read unity manual about this.

What's the deal?

Unity3D has old-fashioned and bizarre .NET Framework like these :)

  • Basically based on .NET Framework 3.5 (forked Mono 2.6)
  • Runtime lacks some types in .NET Framework 3.5 (like System.ComponentModel.AddingNewEventHandler)
  • For iOS, dynamic code emission is forbidden by Apple AppStore.

Because Newtonsoft Json.NET doesn't handle these limitations, errors will welcome you when you use official Json.NET dll targetting .NET 3.5 Framework.

What's done?

Following works are done to make Json.NET support Unity3D.

  • Based on Newtonsoft Json.NET 9.
  • Disable IL generation to work well under AOT environment like iOS.
  • Remove code related with System.ComponentModel.
  • Remove System.Data and EntityKey support.
  • Remove XML support.
  • Remove DiagnosticsTraceWriter support.
  • Workaround for differences between Microsoft.NET & Unity3D-Mono.NET

For Unity.Lite version, additional works are done to make more lite.

  • Remove JsonLinq, JPath (JToken, ...)
  • Remove Bson

Unit Test

Tests in Json.NET are updated to be able to run under UnityEditor Test Runner. All tests pass under Microsoft .NET 3.5 but with UnityEditor some of them fail because there are not-implemented features and bugs in Unity3D-Mono framework.

Test Result:

Profile Passed Failed Ignored
Microsoft.NET 1605 0 1
Unity3D-Mono 1592 13 1

Detailed Description is here to tell you what failed and why.

Unity Compatibility

This library is tested on Unity 4.7, 5.2 and 5.3. For AOT environment like iOS, you need to use IL2CPP instead of obsolute Mono-AOT because IL2CPP handles generic code better than Mono-AOT. With Mono-AOT configuration, AOT related exception would be thrown.

For windows store build, there is a compatibility issue related with UWP. If you have a problem, please read workaround for UWP.

FAQ

Q: MissingMethodException is thrown for ComponentModel.TypeConverter.

MissingMethodException: Method not found:
Default constructor not found...ctor() of System.ComponentModel.TypeConverter.

Make sure that link.xml is added to your project.

Q: ExecutionEngineException is thrown in calling CreateValueInternal.

xecutionEngineException:
  Attempting to call method 'CLASS::.cctor' for which no ahead of time (AOT) code was generated.
at System.Reflection.MonoCMethod.Invoke (...)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal

This exception is thrown because Unity3D strips out unnecessary classes which are actually used by serialization. To fix this problem, just put new CLASS() in your code to prevent Unity3D from removing the class.

Reference: TroubleShootingIPhone

Q: ArgumentNullException is thrown in calling CreateParameterizedConstructor.

ArgumentNullException: Argument cannot be null.
Parameter name: method
at Newtonsoft.Json.Utilities.ValidationUtils.ArgumentNotNull (...)
at Newtonsoft.Json.Utilities.LateBoundReflectionDelegateFactory.CreateParameterizedConstructor (...)

This is similar with the previous case. But this case is tricky because this is caused by Json.NET internal classes such as CollectionWrapper<T>. To fix this problem, put AotHelper.EnsureList<T>() if you use HashSet<T> or AotHelper.EnsureDictionary<TKey, TValue>() if you use Dictionary<TKey, TValue> in working class.

More Repositories

1

Unity3D.IncrementalCompiler

Unity3D Incremental C# Compiler using Roslyn
C#
356
star
2

Unity3D.UselessAttributeStripper

Useless attribute stripper for IL2CPPed executable. It will help for reducing app size for iOS.
C#
76
star
3

Unity3D.UiManager

Essential UI Manager for Unity3D
C#
58
star
4

TicTacToe

Reference game using Akka.Interfaced and TrackableData
C#
56
star
5

Unity3D.ThaiFontAdjuster

Utility to render Thai text correctly in Unity3D, especially for positioning tone mark (ก์กิ์ป์ปิ์ฎุญุ).
C#
55
star
6

Akka.Interfaced

Akka.Interfaced provides the interfaced way for actor messaging in Akka.NET
C#
52
star
7

UniGet

The package manager for Unity3D.
C#
34
star
8

TrackableData

Simple library to track changes of poco, list and dictionary.
C#
24
star
9

ExcelJsonTable

Excel Add-In for Importing and Exporting Json Table
C#
23
star
10

Akka.ProjectScaffolding

Akka.NET + Akka.Interfaced + Unity3D Project Scaffolding
C#
21
star
11

LidgrenUdpNet

Modified version of [lidgren-network-gen3](https://github.com/lidgren/lidgren-network-gen3).
C#
20
star
12

NetLegacySupport

Library helps supporting old .NET frameworks like .NET 2.0 and 3.5.
C#
20
star
13

Snake

Reference game using EntityNetwork, Akka.Interfaced and TrackableData
C#
18
star
14

Akka.Interfaced.SlimSocket

Akka.Interfaced over SlimSocket
C#
13
star
15

EntityNetwork

Entity Network System for Online Game
C#
12
star
16

Common.Logging.Unity3D

Common Logging (A portable logging abstraction for .NET) for Unity3D
C#
11
star
17

Akka.Cluster.Utility

Utilities for Akka.Cluster
C#
10
star
18

TemplateTable

Dictionary container for containing game object template.
C#
9
star
19

Chatty

Demo chat application using Akka.Interfaced and SlimSocket
C#
8
star
20

TypeAlias

Library that makes the unique alias of types in .NET.
C#
6
star
21

AsyncWorker

.NET asynchronous worker to schedule many "async" work in an easy way.
C#
5
star
22

SqlProcBinder

SQL Stored Procedure Binder for .NET
C#
4
star
23

CodeWriter

Helper class for generating code concisely.
C#
4
star
24

LumberjackClient

Library for transporting log data to Logstash via Lumberjack protocol.
C#
3
star
25

BuildToolkit

Build toolkit for SaladLab projects
F#
3
star
26

saladlab.github.io

SaladLab blog http://saladlab.github.io
HTML
1
star
27

Aim.ClusterNode

Basic bootstrap module for running cluster node on Akka.Interfaced Module.
C#
1
star