Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3614518
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:15:31+00:00 2026-05-18T22:15:31+00:00

Today, I was cleaning up some of my code with FXCop and it complained

  • 0

Today, I was cleaning up some of my code with FXCop and it complained about a Attribute class I had with this violation.

CA1019: Define accessor for attribute argument.

On this page, http://msdn.microsoft.com/en-us/library/ms182136.aspx there is more information, but I still do not get the reason for this as it seems to me more verbose and less relevant.

It gives two codes samples.

using System;

namespace DesignLibrary
{
// Violates rule: DefineAccessorsForAttributeArguments.

[AttributeUsage(AttributeTargets.All)]
public sealed class BadCustomAttribute :Attribute 
{
  string data;

  // Missing the property that corresponds to 
  // the someStringData parameter.

  public BadCustomAttribute(string someStringData)
  {
     data = someStringData;
  }
}


// Satisfies rule: Attributes should have accessors for all arguments.
[AttributeUsage(AttributeTargets.All)]
public sealed class GoodCustomAttribute :Attribute 
{
   string data;

   public GoodCustomAttribute(string someStringData)
   {
      data = someStringData;
   }
   //The constructor parameter and property
   //name are the same except for case.

   public string SomeStringData
   {
      get 
      {
         return data;
      }
   }
}
}

I don’t understand why the SomeStringData property is required. Isn’t the someStringData a parameter? Why does it need to have its own property if it is already stored in another property?

Actually, mine is a little different as it looks like this.

[AttributeUsage(AttributeTargets.Property)]
public sealed class ExampleAttribute : Attribute
{
    public ExampleAttribute(string attributeValue)
    {
        this.Path = attributeValue;
    }

    public string Name
    {
        get;
        set;
    }

    // Add to add this to stop the CA1019 moaning but I find it useless and stupid?
    public string AttributeValue
    {
        get
        {
            return this.Name;
        }
    }
}

Rather than a private field, I have used a public autoproperty, I had to add the last part to make the warning stop but I don’t see the point and it also adds another public field to this class, which is redundant, and seems less clean.

That said, I assume that this warning is raised for a reason so what good reason I am missing here?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T22:15:32+00:00Added an answer on May 18, 2026 at 10:15 pm

    FxCop is complaining because your existing property doesn’t match the parameter name.
    Therefore, it doesn’t realize that the parameter actually is exposed.

    You should rename the property or parameter to match (except for case), or suppress the warning.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Today I had a coworker suggest I refactor my code to use a label
Today at work we came across the following code (some of you might recognize
Today when I was in computer organization class, teacher talked about something interesting to
Today I had a discussion with a colleague about nested functions in Javascript: function
Today I encountered the following situation: (pseudo code) class MyClass { public void workOnArray(Object[]
Today, I ran into this weird problem with a user using Mac OS X.
Today I was listening to the Hanselminutes show about .NET 3.5 SP1...What's inside ,
Today I stumbled about a Problem which seems to be a bug in the
today i have a simple an understable problem for me . Next code: alphavar
Today I started thinking about a new project, and I found one. The goal

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.