-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
System.Text.Json code generator: cannot convert from 'System.Text.Json.Utf8JsonWriter' to 'System.IO.Stream' #58118
Comments
Tagging subscribers to this area: @eiriktsarpalis, @layomia Issue DetailsMy library contains the following public class BouncedEvent
{
public BouncedEvent()
{
EventType = EventType.Bounce;
}
[JsonPropertyName("ip")]
public string IpAddress { get; set; }
[JsonPropertyName("reason")]
public string Reason { get; set; }
[JsonPropertyName("status")]
public string Status { get; set; }
[JsonPropertyName("type")]
public BounceType Type { get; set; }
}
[JsonConverter(typeof(StringEnumConverter<BounceType>))]
public enum BounceType
{
[EnumMember(Value = "bounce")]
HardBounce,
[EnumMember(Value = "blocked")]
Block
} System.Text.Json code generator generates the following snippet: private static void BouncedEventSerialize(global::System.Text.Json.Utf8JsonWriter writer, global::MyLibrary.Models.BouncedEvent value)
{
if (value == null)
{
writer.WriteNullValue();
return;
}
writer.WriteStartObject();
writer.WriteString(ipPropName, value.IpAddress);
writer.WriteString(reasonPropName, value.Reason);
writer.WriteString(statusPropName, value.Status);
writer.WritePropertyName(typePropName);
// The following line is causing the errors described bellow
global::System.Text.Json.JsonSerializer.Serialize(writer, value.Type, global::MyLibary.Utilities.MyJsonSerializerContext.Default.BounceType);
writer.WriteEndObject();
} VS.NET refuses to compile and reports the following errors:
I'm using the latest daily build of System.Text.Json: 6.0.0-rc.2.21424.25 ❯ dotnet --info Runtime Environment: Host (useful for support): .NET SDKs installed:
|
The |
@eiriktsarpalis I found more information and it turns out the problem has nothing to do with converting from 'System.Text.Json.Utf8JsonWriter' to 'System.IO.Stream' as the error message leads you to believe. This error message was simply misleading. The confusion come from the fact that Visual Studio 2019 obscures the underlying issue. Switching to VS.NET 2022 reveals more detailed information about the problem (it has to do with two classes sharing the same name). I raised a different issue with repro steps for the underlying problem. This confusion could have been avoided if VS.NET 2019 displayed the same level of details that VS.NET 2022 does. It's also surprising that symptoms and the feedback provided in the "Error List" window for a given problem are so different depending on the version of VS |
My library contains the following
BouncedEvent
class andBounceType
enum:System.Text.Json code generator generates the following snippet:
VS.NET refuses to compile and reports the following errors:
I'm using the latest daily build of System.Text.Json: 6.0.0-rc.2.21424.25
❯ dotnet --info
.NET SDK (reflecting any global.json):
Version: 5.0.400
Commit: ...snip...
Runtime Environment:
OS Name: Windows
OS Version: 10.0.22000
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\5.0.400\
Host (useful for support):
Version: 6.0.0-preview.7.21377.19
Commit: ...snip...
.NET SDKs installed:
2.1.816 [C:\Program Files\dotnet\sdk]
3.1.302 [C:\Program Files\dotnet\sdk]
3.1.400 [C:\Program Files\dotnet\sdk]
3.1.411 [C:\Program Files\dotnet\sdk]
5.0.103 [C:\Program Files\dotnet\sdk]
5.0.104 [C:\Program Files\dotnet\sdk]
5.0.205 [C:\Program Files\dotnet\sdk]
5.0.302 [C:\Program Files\dotnet\sdk]
5.0.400 [C:\Program Files\dotnet\sdk]
6.0.100-preview.7.21379.14 [C:\Program Files\dotnet\sdk]
The text was updated successfully, but these errors were encountered: