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

Fix S4004: Rule should not raise a violation when [DataMember] is applied #795

Closed
cmenzi opened this issue Sep 24, 2017 · 0 comments
Closed
Assignees
Labels
Type: False Positive Rule IS triggered when it shouldn't be.
Milestone

Comments

@cmenzi
Copy link

cmenzi commented Sep 24, 2017

Description

I like this rule very much, because it's forcing good encapsulation. But when using [DataContract]s for DTOs, it's hard to fulfill this rule.

Repro steps

[DataContract]
public class Message
{
    [DataMember]
    [Required]
    public string Id { get; set; }

    [DataMember]
    [Required]
    public string MessageBody { get; set; }

    [DataMember]
    [Required]
    public Dictionary<string, string> Properties { get; set; }
}

Expected behavior

The rule should not raise, when [DataContract] attribute is attached to the class or maybe more explicitly [DataMember] is on the property.

Actual behavior

The rule raises a violation.

Known workarounds

  • Implement custom serialization/deserialization for the class.
  • Use custom backing fields and attach to attribute to datamember

Related information

  • SonarC# 6.5.0.27846
  • Visual Studio 2017.3
  • MSBuild 15.3.409.57025
@cmenzi cmenzi changed the title S4004 should raise when [DataContract] is applied S4004 should not raise a violation when [DataContract] or [DataMember] is applied Sep 24, 2017
@Evangelink Evangelink added this to the 6.5 milestone Oct 4, 2017
@Evangelink Evangelink added Area: RSPEC Type: False Positive Rule IS triggered when it shouldn't be. labels Oct 4, 2017
@Evangelink Evangelink changed the title S4004 should not raise a violation when [DataContract] or [DataMember] is applied Fix S4004: Rule should not raise a violation when [DataContract] or [DataMember] is applied Oct 4, 2017
@Evangelink Evangelink removed this from the 6.5 milestone Oct 12, 2017
@Evangelink Evangelink changed the title Fix S4004: Rule should not raise a violation when [DataContract] or [DataMember] is applied Fix S4004: Rule should not raise a violation when[DataMember] is applied Oct 16, 2017
@Evangelink Evangelink changed the title Fix S4004: Rule should not raise a violation when[DataMember] is applied Fix S4004: Rule should not raise a violation when [DataMember] is applied Oct 16, 2017
@Evangelink Evangelink self-assigned this Oct 16, 2017
@Evangelink Evangelink added this to the 6.6 milestone Oct 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: False Positive Rule IS triggered when it shouldn't be.
Projects
None yet
Development

No branches or pull requests

2 participants