JSONMessage does not handle variant properly in .Net

As indicated before, I’m using RO SDK to “open” parts of our applications to the world.
This requires generating JSON for objects that have Variant properties. While doing it in Delphi gives a coherent JSON that can get read quite well, it is now time to “port” the code to the C#/.Net part and I’m thus using the following code to generate the JSON:

        using JsonMessage JSONMessage = new();

        JSONMessage.InitializeMessage(null, "dummy", "dummy", MessageType.Response);
        JSONMessage.Write("variables", ROVariables, typeof(TVariablesArray[]), StreamingFormat.Default;

This does not crash but gives strange results when placing a double or a bool inside the Variant property:


As you can see, the two values are output as string when I would have expected a direct JSON value, just like what happens with Delphi: "Value":40.5 and "Value":true.
What’s even worse is that it is using localized values which means trouble later on.
Note: I have not used a int value in this example, but it behaves just like double, giving a quoted string instead of a direct value.

There is also a problem when doing the reverse, that is read a JSON content to instantiate an array of objects like this:

        using JsonMessage JSONMessage = new();


        return (TVariablesArray[])JSONMessage.Read("variables", typeof(TVariablesArray[]), StreamingFormat.Default);

There, if I give a valid JSON as created from Delphi, I do get the appropriate number of items in the array but the Variant property is not always set to a valid type:

  • For DateTime, the value in JSON is "2022-10-05T17:55:21.735" but I get a string instead of the expected DateTime instance and that string is equal to the source string
  • For Date, the value in JSON is "2022-10-05T00:00:00" and I get a valid DateTime instance just fine.
  • For Int, the value in JSON is 72 and I get a double instance. Odd as Delphi gives a valid Integer, but not unrealistic.
  • For Double, the value in JSON is 40.5 and I get a valid double instance
  • For Boolean, the value in JSON is true but I get a null value which is completely strange

So double and string values are fine, int is acceptable, DateTime seems not to like having a time portion but boolean is completely off the mark. All this despite the C# code being completely similar to the Delphi code that works fine.

We are using version which I agree is a bit old, but there are no mentions of JSON related changes in the what’s new documentation.

Is there anything that I missed here?
What can I try to overcome those obstacles?


Can you create a simple testcase that reproduces this issue, pls?
You can drop email to support@ for keeping privacy

Note: your testcase allows to solve this issue faster

Here a simplified example:
ro json variants.zip (13.4 KB)

It shows the same concepts both in Delphi and C# (VS2022)
As you will see, the C# project exhibit the behavior explained above, while the Delphi project works just fine.

Logged as bugs://D19289.

bugs://D19289 was closed as fixed.

@EvgenyK the bot says this has been fixed, but could you shed a bit more light on the situation?
What is the resolution, does it require an upgrade, is there a workaround… ?



You can drop email to support@ and I can give you details what was changed.
You can rebuild Remoting SDK assemblies manually as described at the Platform Frequently Asked Questions page

1 Like