Closed
Description
First off, thanks for the great project. It's made things much easier for me!
Describe the bug
After upgrading to UnitsNet version 5.5.0, upon serialization, I get the following error. Version 5.4.0 works fine.
Error: System.MissingMethodException: Method not found: 'System.Decimal UnitsNet.IDecimalQuantity.get_Value()'.
at UnitsNet.Serialization.JsonNet.UnitsNetBaseJsonConverter`1.ConvertIQuantity(IQuantity quantity)
at UnitsNet.Serialization.JsonNet.UnitsNetIQuantityJsonConverter.WriteJson(JsonWriter writer, IQuantity value, JsonSerializer serializer)
at Newtonsoft.Json.JsonConverter`1.WriteJson(JsonWriter writer, Object value, JsonSerializer serializer)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeConvertable(JsonWriter writer, JsonConverter converter, Object value, JsonContract contract, JsonContainerContract collectionContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)
at Newtonsoft.Json.JsonSerializer.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
at Newtonsoft.Json.JsonConvert.SerializeObjectInternal(Object value, Type type, JsonSerializer jsonSerializer)
at Newtonsoft.Json.JsonConvert.SerializeObject(Object value, Type type, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.SerializeObject(Object value, JsonSerializerSettings settings)
at Submission#3.<<Initialize>>d__0.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.RunSubmissionsAsync[TResult](ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, StrongBox`1 exceptionHolderOpt, Func`2 catchExceptionOpt, CancellationToken cancellationToken)
To Reproduce
Steps to reproduce the behavior (just an example):
- Add nugets
UnitsNet, 5.5.0
,UnitsNet.Serialization.JsonNet, 5.0.0
andNewtonsoft.Json, 13.0.2
to a.NET 6.0
project - Add code to run the example found here: UnitsNet.Serialization.JsonNet with Json.NET (Newtonsoft)
- Build using Visual Studio 2022 v17.5.1
- See error above.
Expected behavior
I expect it to serialize output as shown in the example in the docs:
{
"Name": "Raiden",
"Weight": {
"Unit": "MassUnit.Kilogram",
"Value": 90.0
}
}
Additional context
I created a VS Code Polyglot Notebook that will reproduce this error as well.
JsonMissingMethodException.zip