Skip to content

MissingMethodException when serializing to Json #1216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
drepamig opened this issue Mar 1, 2023 · 4 comments
Closed

MissingMethodException when serializing to Json #1216

drepamig opened this issue Mar 1, 2023 · 4 comments
Labels

Comments

@drepamig
Copy link

drepamig commented Mar 1, 2023

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):

  1. Add nugets UnitsNet, 5.5.0, UnitsNet.Serialization.JsonNet, 5.0.0 and Newtonsoft.Json, 13.0.2 to a .NET 6.0 project
  2. Add code to run the example found here: UnitsNet.Serialization.JsonNet with Json.NET (Newtonsoft)
  3. Build using Visual Studio 2022 v17.5.1
  4. 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

@drepamig drepamig added the bug label Mar 1, 2023
@tmilnthorp
Copy link
Collaborator

tmilnthorp commented Mar 1, 2023

@angularsen looks like we need a new version of UnitsNet.Serialization.JsonNet published. I forgot we distribute independently, and #1207 broke this.

@angularsen
Copy link
Owner

Ah yes, easy to forget. I bumped the JSON to match the current UnitsNet version, to trigger a new build and release.

@drepamig Could you take it for a spin and report back if it helps? Should be out shortly.

Release JsonNet/5.5.0 · angularsen/UnitsNet

@drepamig
Copy link
Author

drepamig commented Mar 2, 2023

I just updated both UnitsNet and UnitsNet.Serialization.JsonNet to 5.5.0 and everything is working again. Thanks for such a fast turn around!

@drepamig drepamig closed this as completed Mar 2, 2023
@angularsen
Copy link
Owner

Glad to hear it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants