Description
Description
When using the dotnet 6 System.Text.Json source generator on a class or record that contains a delegate type (Func, Action), a CS0149 Method Name Expected error is thrown from the generated g.cs file. This happens even if using the [JsonIgnore] property.
Reproduction Steps
Create a dotnet 6 project and create a new class/record with the source generator. The following code will reproduce the problem minimally:
public record TestRecord(string Test, Func<string, bool> Callback);
[JsonSerializable(typeof(TestRecord))]
public partial class TestRecordGenerationContext : JsonSerializerContext { }
Expected behavior
The expected behavior is that the g.cs files are generated without error and the [JsonIgnore] attribute is properly used for delegate types.
Actual behavior
Currently, the g.cs files are generated but throw a CS0149 Method Name Expected error.
Regression?
No response
Known Workarounds
Only workaround I've used so far is to completely remove the delegate types as member properties or member variables from the class or converting them to a method (if possible for your requirements) so the source generator ignores it.
Configuration
- Which version of .NET is the code running on? dotnet 6.0
- What OS and version, and what distro if applicable? Windows 10 64-bit
- What is the architecture (x64, x86, ARM, ARM64)? x64
- Do you know whether it is specific to that configuration? Unsure
- If you're using Blazor, which web browser(s) do you see this issue in? I am using Blazor, but this isn't a runtime issue
Other information
For where the issue might be, perhaps the source generator does properly ignore the member for the generated serialization code, but it doesn't ignore it when traversing the member hierarchy to determine which classes need serialization code generated. Not sure.