Skip to content

BinaryData + JSON source gen produces compiler warnings #81702

@krwq

Description

@krwq

EDIT by @eiriktsarpalis to reflect more recent error modes

In #73448 we've added internal converter for BinaryData but that's not working with JSON source-gen.

Repro

using System.Text.Json.Serialization;

[JsonSerializable(typeof(BinaryData))]
partial class MyContext : JsonSerializerContext { }

Expected behavior:

Compiles and works when you serialize/deserialize

Actual

warning SYSLIB1041: The 'JsonConverterAttribute' type 'System.BinaryDataConverter' specified on member 'System.BinaryData' is not a converter type or does not contain an accessible parameterless constructor.

API Proposal

We should make the constructor of the already included custom converter public:

namespace System;

[JsonConverter(typeof(BinaryDataConverter))]
public partial class BinaryData { }

-internal sealed class BinaryDataConverter : JsonConverter<BinaryData> { }
+namespace System.Text.Json.Serialization;
+
+public sealed class BinaryDataConverter : JsonConverter<BinaryData> { }

Metadata

Metadata

Labels

api-approvedAPI was approved in API review, it can be implementedarea-System.MemoryblockingMarks issues that we want to fast track in order to unblock other important work

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions