Azure / azure-iot-sdk-csharp

A C# SDK for connecting devices to Microsoft Azure IoT services
Other
463 stars 493 forks source link

[Bug Report] JsonConvert.DefaultSettings is being modified #3366

Closed citruspress closed 9 months ago

citruspress commented 11 months ago

Description of the issue

This library modifies JsonConvert.DefaultSettings. For example in this commit: https://github.com/Azure/azure-iot-sdk-csharp/commit/c1d6e97ab28b6dd1fccd9ad2fad881dc5d906488. In our case we have previously depended on using our own default settings for a lot of other things. Upgrading the DeviceClient means we have to manually specify the settings everywhere we serialize or deserialize anything now.

It doesn't feel correct to modify a global static from a library where the application using the library may previously depend on it.

Code sample exhibiting the issue

We use these settings by setting the DefaultSettings when configuring our app:

new JsonSerializerSettings
{
    Formatting = Formatting.Indented,
    ContractResolver = new CamelCasePropertyNamesContractResolver()
};

When doing the following after creating the device client:

var messageContent = JsonConvert.SerializeObject(new { Test = "test" }, Formatting.None);

it's not using our settings, but it seems like it's rather settings being set by this library.

Uladzimir-Lashkevich commented 11 months ago

Seems related to https://github.com/Azure/azure-iot-sdk-csharp/issues/3358

timtay-microsoft commented 9 months ago

Closing this thread as it is a duplicate of #3358 as noted above.