4

I am working on a Windows Forms project that uses Telerik RadControls, including the RadGridView. The control in question automatically creates a RadGridView instance named MasterTemplate as a class member, as well as the one I named, due to the way it works internally.

This causes Visual Studio to give me a "The field [...] is never used" warning for each RadGridView in the entire project, of which there are many.

  • Editing the .designer.cs file is pointless as it would be edited by the designer itself.
  • While it may be possible to suppress all warnings of this type, I don't want to do so because it would also hide warnings about fields that I created.
  • Leaving the warnings there is unnecessarily cluttering the Error List window, so I have to hide all warnings if I want to see only the errors. I then re-enable the display of the warnings and have to read the list carefully to see if there are any "legitimate" warnings in it.

Is it in any way possible to tell Visual Studio to "never bother me with this warning about this variable again, but do keep telling me about other warnings"?

DavidRR
  • 18,291
  • 25
  • 109
  • 191
George T
  • 698
  • 9
  • 18
  • Did you try #pragma warning? See it here: https://msdn.microsoft.com/en-us/library/441722ys.aspx – jsanalytics Jul 16 '15 at 14:02
  • From the example shown in that link, i would say the scope is a particular source code file, which is a pretty good level of granularity. – jsanalytics Jul 16 '15 at 14:06
  • @jstreet: Thanks, that seems to work. I wonder though if it's "safe" in a .designer.cs file. A simple change in the editor didn't affect it but something else may. – George T Jul 16 '15 at 14:09
  • Editing a designer.cs file is never recommended. Besides you may need to do it again in case it gets re-generated... But it will get rid of annoying warnings. – jsanalytics Jul 16 '15 at 14:12
  • @jstreet: I suppose that's the best that can be done. Thanks for the information! – George T Jul 16 '15 at 14:16

1 Answers1

2

From Microsoft's documentation for Visual Studio, How to: Suppress compiler warnings:

Suppress specific warnings for Visual C# or F# 

Use the Build property page to suppress specific warnings for C# and F# projects.

  1. In Solution Explorer, choose the project in which you want to suppress warnings.

  2. On the menu bar, choose View > Property Pages.

  3. Choose the Build page.

  4. In the Suppress warnings box, specify the error codes of the warnings that you want to suppress, separated by semicolons.

  5. Rebuild the solution.

According to this documentation, the ability to suppress the display of specified warnings was made available at least as far back as Visual Studio 2015. I can confirm that this guidance is working for me in Visual Studio 2017. Also, I have found that whitespace is permitted after the semicolon (and before as well, if you like). For example:

CS1587; CS1591

Finally, the linked documentation indicates that warnings can also be suppressed for the following:

  • Visual C++
  • Visual Basic
  • NuGet packages
Community
  • 1
  • 1
DavidRR
  • 18,291
  • 25
  • 109
  • 191