Skip to content
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

Startup diagnostic serialization fails when diagnostic entries include System.Type properties #6813

Closed
abparticular opened this issue Aug 21, 2023 · 0 comments · Fixed by #6829 or #6830

Comments

@abparticular
Copy link
Contributor

abparticular commented Aug 21, 2023

Describe the bug

Description

NServiceBus 8.1.1 included replacing SimpleJson with System.Text.Json in the HostStartupDiagnosticsWriter class.

However, System.Text.Json does not support System.Type serialization out of the box, due to security concerns. At least one transport (there may be others) includes a System.Type property in a startup diagnostic entry, which causes serialization of startup diagnostics to fail.

Steps to reproduce

This behavior can be reproduced by enabling delayed delivery in the Simple MSMQ Transport usage sample.

Relevant log output

2023-08-21 12:32:59.899 ERROR Failed to serialize startup diagnostics
System.NotSupportedException: Serialization and deserialization of 'System.Type' instances are not supported. Path: $.TimeoutStorageType. ---> System.NotSupportedException: Serialization and deserialization of 'System.Type' instances are not supported.
   at System.Text.Json.Serialization.Converters.UnsupportedTypeConverter`1.Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
   at System.Text.Json.Serialization.JsonConverter`1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1.GetMemberAndWriteJson(Object obj, WriteStack& state, Utf8JsonWriter writer)
   at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryWrite(Utf8JsonWriter writer, T value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1.TryWriteAsObject(Utf8JsonWriter writer, Object value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.Converters.DictionaryOfTKeyTValueConverter`3.OnWriteResume(Utf8JsonWriter writer, TCollection value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonDictionaryConverter`3.OnTryWrite(Utf8JsonWriter writer, TDictionary dictionary, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1.WriteCore(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
   --- End of inner exception stack trace ---
   at System.Text.Json.ThrowHelper.ThrowNotSupportedException(WriteStack& state, NotSupportedException ex)
   at System.Text.Json.Serialization.JsonConverter`1.WriteCore(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.JsonSerializer.WriteCore[TValue](Utf8JsonWriter writer, TValue& value, JsonTypeInfo`1 jsonTypeInfo)
   at System.Text.Json.JsonSerializer.WriteString[TValue](TValue& value, JsonTypeInfo`1 jsonTypeInfo)
   at NServiceBus.HostStartupDiagnosticsWriter.<Write>d__1.MoveNext() in /_/src/NServiceBus.Core/Hosting/StartupDiagnostics/HostStartupDiagnosticsWriter.cs:line 30

Symptoms

Startup diagnostics file is not generated

Who's affected

Users of both NServiceBus 8.1.1 and the MSMQ transport with delayed delivery enabled

Root cause

The MSMQ transport includes a System.Type property as part of a diagnostics entry which the System.Text.Json serializer does not support.

Backported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment