Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppressing obsolete warnings in VB.NET

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.

like image 537
Shahar Mosek Avatar asked May 13 '09 12:05

Shahar Mosek


People also ask

How do I suppress a warning in Visual Studio?

Suppress specific warnings for Visual C# or F# Or, select the project node and press Alt+Enter. Choose Build, and go to the Errors and warnings subsection. In the Suppress warnings or Suppress specific warnings box, specify the error codes of the warnings that you want to suppress, separated by semicolons.

How do you suppress code Analysis warnings?

If you migrate a project to Visual Studio 2019, you might suddenly be faced with a large number of code analysis warnings. If you aren't ready to fix the warnings, you can suppress all of them by selecting Analyze > Build and Suppress Active Issues.

How do you suppress warnings?

Use of @SuppressWarnings is to suppress or ignore warnings coming from the compiler, i.e., the compiler will ignore warnings if any for that piece of code. 1. @SuppressWarnings("unchecked") public class Calculator { } - Here, it will ignore all unchecked warnings coming from that class.


2 Answers

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>
like image 111
JaredPar Avatar answered Sep 21 '22 00:09

JaredPar


In VS.NET you can right click on and suppress code analysis warnings. This will add the attribute for you.

However, the "don't use obsolete APIs" warning is not coming from code analysis, and so the SurpressMessage attibute won't work. This is a compiler warning.

For VS.NET you'd need to switch off this warning with...

/nowarn:0618

... at the command line (or just adding "0618" into the Suppress Warnings field on the csproj properties). You should do the same with whatever the VB warning number is.

like image 28
Martin Peck Avatar answered Sep 24 '22 00:09

Martin Peck