Skip to content

[Bug]: Reactive attribute with partial property copies JsonPropertyName attribute #245

@sdargaud

Description

@sdargaud

Describe the bug 🐞

When the [Reactive] attribute is used on a partial property inside a partial class, if you add a JsonPropertyName attribute, it is copied in the generated partial class code and the compilation fails with :
Duplicate 'global::System.Text.Json.Serialization.JsonPropertyNameAttribute' attribute

Step to reproduce

Create the following class:

public partial class MyClass : ReactiveObject
{
    [Reactive]
    [JsonPropertyName("test")]
    public partial string MyProperty { get; set; }
}

And go to the generated partial class, you will see the same attribute generated:

public partial class MyClass
{
    [global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ReactiveGenerator", "2.2.0.0")]
    private string _myProperty;
    /// <inheritdoc cref="_myProperty"/>
    [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
    [global::System.Text.Json.Serialization.JsonPropertyNameAttribute("test")]
    public partial string MyProperty
    { 
        get => _myProperty;
        [global::System.Diagnostics.CodeAnalysis.MemberNotNull("_myProperty")]
        set => this.RaiseAndSetIfChanged(ref _myProperty, value);
    }
}

Then, the project does not compile

Reproduction repository

https://github.com/reactiveui/ReactiveUI

Expected behavior

The attribute should not be re-generated.

Screenshots 🖼️

No response

IDE

Rider Windows

Operating system

Windows 11

Version

2.2.4

Device

No response

ReactiveUI Version

20.3.1

Additional information ℹ️

It was working fine with version 2.1.27

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions