Suppressing obsolete warnings in VB.NET

Shahar Mosek picture Shahar Mosek · May 13, 2009 · Viewed 10k times · Source

I have VB.NET code in Visual Studio 2008 using an obsolete method and would like to suppress the warning. Unfortunately, following the recommendation is not a good solution, because it requires using a different class, which works differently, in important ways.

I'm trying to suppress the warning using System.Diagnostics.CodeAnalysis.SuppressMessage, but I don't know what to write as the parameters for the attribute and can't find any relevant reference.

I should also say that, right-clicking on the error in the error list I don't have any 'Suppress Message' option.

Answer

JaredPar picture JaredPar · May 13, 2009

If you're using Visual Studio you can do the following.

  1. Right click on the project and select "unload"
  2. Right click on the project and select "Edit SomeProjectName.vbproj"
  3. You should see two XML element tags with the name "NoWarn". Add the number 40000 to the list of numbers already present (make sure to do this for every NoWarn tag in the file)
  4. Save the file
  5. Right click on the project and select reload (you'll have to close the .vbproj file)

This will get rid of the warning. The number 40000 is the VB.Net error number for the obselete warning. You can suppress any warning in this fashion.

Note: If the NoWarn tag is not present, add it to the main PropertyGroup element with the following values

<NoWarn>40000</NoWarn>