Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. FxCop Performance Warning CA1822

FxCop Performance Warning CA1822

Scheduled Pinned Locked Moved C#
performancehelpquestion
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Subin Mavunkal
    wrote on last edited by
    #1

    Hi Developers, In CA1822 , microsoft performance warnings ask some methods to static.It wont be an issue if we make a private method static , but an issue pop-ups when we make a public method , or an interface implementation to static.It will severely affect the logic.Is there any alternate solution ?

    D M realJSOPR 3 Replies Last reply
    0
    • S Subin Mavunkal

      Hi Developers, In CA1822 , microsoft performance warnings ask some methods to static.It wont be an issue if we make a private method static , but an issue pop-ups when we make a public method , or an interface implementation to static.It will severely affect the logic.Is there any alternate solution ?

      D Offline
      D Offline
      DaveyM69
      wrote on last edited by
      #2

      As the method in question isn't accessing instance data it should not be part of an interface anyway. MSDN[^] says:

      It is safe to suppress a warning from this rule for previously shipped code for which the fix would be a breaking change.

      Dave
      Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
      BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

      S 1 Reply Last reply
      0
      • S Subin Mavunkal

        Hi Developers, In CA1822 , microsoft performance warnings ask some methods to static.It wont be an issue if we make a private method static , but an issue pop-ups when we make a public method , or an interface implementation to static.It will severely affect the logic.Is there any alternate solution ?

        M Offline
        M Offline
        Mirko1980
        wrote on last edited by
        #3

        Don't worry too much about that, it's only a warning. If a non-static method don't use any instance-level method or property, FxCop tells you that there are no reasons that method should not be static, and suggest you to make it static. But, if that method is part of an interface implementation (or exposed publicly and alraedy used from other methods), there ARE reasons that should not be static, so you should ignore the warning. If you want, you can use the SuppressMessage attribute to avoid getting the warning for specific methods.

        1 Reply Last reply
        0
        • D DaveyM69

          As the method in question isn't accessing instance data it should not be part of an interface anyway. MSDN[^] says:

          It is safe to suppress a warning from this rule for previously shipped code for which the fix would be a breaking change.

          Dave
          Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
          BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

          S Offline
          S Offline
          Subin Mavunkal
          wrote on last edited by
          #4

          Yes , those are unused methods which are kept for the future usage. Thank You

          1 Reply Last reply
          0
          • S Subin Mavunkal

            Hi Developers, In CA1822 , microsoft performance warnings ask some methods to static.It wont be an issue if we make a private method static , but an issue pop-ups when we make a public method , or an interface implementation to static.It will severely affect the logic.Is there any alternate solution ?

            realJSOPR Offline
            realJSOPR Offline
            realJSOP
            wrote on last edited by
            #5

            If your app compiles without errors and runs without crashing, you can safely ignore pretty much any warnings FXCop generates. It just provides suggestions on "best practice for coding style. It is not intended to be an omnipotent oracle of "how to code". Throw away the crutch, and learn to stand on your own two feet.

            ".45 ACP - because shooting twice is just silly" - JSOP, 2010
            -----
            You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
            -----
            "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

            S 1 Reply Last reply
            0
            • realJSOPR realJSOP

              If your app compiles without errors and runs without crashing, you can safely ignore pretty much any warnings FXCop generates. It just provides suggestions on "best practice for coding style. It is not intended to be an omnipotent oracle of "how to code". Throw away the crutch, and learn to stand on your own two feet.

              ".45 ACP - because shooting twice is just silly" - JSOP, 2010
              -----
              You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
              -----
              "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

              S Offline
              S Offline
              SledgeHammer01
              wrote on last edited by
              #6

              I agree with this answer. I am *SUPER* anal about my code formatting. I mean, really, super duper anal. So I thought FxCop would be my new BFF. Sadly no. I found most of its demands to be too pretentious for my tastes and quickly uninstalled it.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups