How do I suppress FxCop rule 'DoNotCatchGeneralExceptionTypes' with SupressMessage?

☆樱花仙子☆ 提交于 2019-11-27 01:56:49

问题


I've got code that catches everything and logs it. I don't normally do this, but I'm writing an HTTP handler and want to return an appropriate HTTP code. Anyway, I'm putting the following at the top of my method:

[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "We just log the exception and return an HTTP code")]

FxCop is seemingly ignoring this, which is very frustrating. Especially as it's also ignoring all of my compound word overrides too!

Any idea why it's doing this? I'm using FxCop 10 which is part of the Windows 7/.NET 4 SDK.


回答1:


  1. In Solution Explorer, right-click your project and choose Properties.
  2. In the Properties window, choose the Build tab.
  3. In the Conditional compilation symbols text box, enter CODE_ANALYSIS.
  4. In the code where you want to suppress certain messages, add the namespace System.Diagnostics.CodeAnalysis to the using section.
  5. In FxCop, right-click the message you want to suppress and select Copy As -> SuppressMessage.
  6. In your C# code, paste the SuppressMessage attribute in your code.

Your SupressMessage looks correct, so it could be the missing conditional compilation symbol!

Hope this helps, at least works on my machine ;) Greetz, Tom.

Source



来源:https://stackoverflow.com/questions/3683729/how-do-i-suppress-fxcop-rule-donotcatchgeneralexceptiontypes-with-supressmessa

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!