Exception: JsonSerializationException: Unable to find a constructor to use for type PreparedCardData. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. Path '[0].id', line 3, position 9.


Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewObject (Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonObjectContract objectContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, Newtonsoft.Json.Serialization.JsonProperty containerProperty, System.String id, System.Boolean& createdFromNonDefaultCreator) (at <00000000000000000000000000000000>:0)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) (at <00000000000000000000000000000000>:0)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList (System.Collections.IList list, Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonArrayContract contract, Newtonsoft.Json.Serialization.JsonProperty containerProperty, System.String id) (at <00000000000000000000000000000000>:0)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, System.Object existingValue, System.String id) (at <00000000000000000000000000000000>:0)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, System.Boolean checkAdditionalContent) (at <00000000000000000000000000000000>:0)
Newtonsoft.Json.JsonSerializer.DeserializeInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType) (at <00000000000000000000000000000000>:0)
Newtonsoft.Json.JsonConvert.DeserializeObject (System.String value, System.Type type, Newtonsoft.Json.JsonSerializerSettings settings) (at <00000000000000000000000000000000>:0)
Newtonsoft.Json.JsonConvert.DeserializeObject[T] (System.String value, Newtonsoft.Json.JsonSerializerSettings settings) (at <00000000000000000000000000000000>:0)
PlayerManager.LoadPreparedCardData () (at <00000000000000000000000000000000>:0)
PCencyclopediaPopUp.Start () (at <00000000000000000000000000000000>:0)

[오류 로그]

 

오늘 앱을 빌드해 테스트를 해보는데

 

갑자기

 

Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types

 

라는 오류가 생겨서 보니

 

역직렬화 할때에 기본 생성자 부분에서 문제가 생기는 것 같았다.

 

그래서 Newtonsoft를 다시 깔아도보고

 

기본생성자 위에 [JsonConstructor]를 붙여 보기도 했는데

 

빌드시 자꾸 같은 문제가 반복되었다.

 

 

그래서 잘 생각해보니

 

GPGS랑 Admob을 설정하면서 환경설정을 살짝 건든 것이 있어서

 

다시금 살펴 보았다.

 

그랬더니...

 

 

Build Settings - Project Settings - Player - Other Settings - Optimization - Managed Stripping Level 부분을

High로 설정 했었다.

 

이 설정에 대해서 다시 알아보니 

 

High 설정일 때 공격적인 제거

  • Managed Stripping Level을 Low → Medium → High 순으로 올릴수록, UnityLinker가 더 공격적으로 “사용되지 않는 코드”를 제거합니다.
  • 이때, “어느 부분에서 사용하는지”를 리플렉션으로만 참조하고 있으면 UnityLinker가 이를 사용된 코드로 인식하지 못해 제거해 버릴 수 있습니다.

 

라고 설명이 나와있었다.

 

Managed Stripping Level이 High로 설정되어서

역직렬화 과정에서 필요한 코드(예: 기본 생성자가 실제로 사용되지 않는다고 판단되어

빌드 과정에서 제거가 되었던 것이다.

 

 

 

이런 문제는 IL2CPP 환경에서 특히 많이 발생하는 문제라고도 한다.

 

 

이후  다시 설정을 High -> Low로 바꿔주니 다시금 제대로 역직렬화가 진행 되었다.

 

 

 

(다행이다)

반응형

+ Recent posts