KhronosGroup / glTF-CSharp-Loader

C# Reference Loader for glTF
Other
219 stars 58 forks source link

Support for compiling with "Trim unused code" #50

Open BoyBaykiller opened 1 year ago

BoyBaykiller commented 1 year ago

My C# application uses glTFLoader for loading gltf models. I'd like to be able to publish the code with the "Trim unused code" compiler option as it drastically reduces binary size.

However when running the exectuable I get this exception.

Unhandled exception. Newtonsoft.Json.JsonSerializationException: Unable to find a constructor to use for type glTFLoader.Schema.Gltf. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. Path 'asset', line 2, position 10.
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewObject(JsonReader, JsonObjectContract, JsonProperty, JsonProperty, String, Boolean& )
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader, Type, JsonContract, JsonProperty, JsonContainerContract, JsonProperty, Object)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader, Type, JsonContract, JsonProperty, JsonContainerContract, JsonProperty, Object)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader, Type, Boolean)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader, Type)
   at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader, Type)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String, Type, JsonSerializerSettings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String, JsonSerializerSettings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String)
   at glTFLoader.Interface.LoadModel(Stream)
   at glTFLoader.Interface.LoadModel(String)

This only happens when compiling with "Trim unused code".

bghgary commented 1 year ago

I've never heard of this option. If someone wants to research and provide a solution, that'll be great. Otherwise, I'm not sure what we can do with this.