FxCop Performance Warning CA1822
-
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 ?
-
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 ?
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) -
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 ?
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.
-
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)Yes , those are unused methods which are kept for the future usage. Thank You
-
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 ?
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 -
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, 1997I 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.