14

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Shahar Mosek
  • 1,922
  • 3
  • 17
  • 27
  • 3
    Obsolete things are usually obsolete for a reason however, and so you should definitely have a "TODO" in the code to remind you to update the method to the new way as soon as you have some free development cycles. – DevinB May 13 '09 at 13:04
  • 2
    Unfortunately, there is no way to remove the obsolete code without breaking backwards compatibility. – Shahar Mosek May 14 '09 at 06:41

3 Answers3

18

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>
JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
  • 4
    Note that this will get rid of _all_ obsolete warnings in your project, not just this one instance... – bdukes May 13 '09 at 14:42
  • Also note that you have to delete any empty NoWarn tags from the main group for this to work. – turbo Oct 13 '15 at 00:38
4

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Martin Peck
  • 11,440
  • 2
  • 42
  • 69
0

I was able to resolve this with JaredPar's answer in my VB Project, thanks!

I did had same warning for my C# test project that I got removed by adding 618 in suppress warning section of Build Tab in Project Properties.

Please remember the Error Codes for VB and C# are different.


If one want to correct the these warnings then one need to install and use ODP.NET for Microsoft OracleClient Developers

Microsoft is deprecating System.Data.OracleClient, also known as Microsoft OracleClient. Microsoft OracleClient provider developers can use this opportunity to reevaluate which data provider to use for current and upcoming projects. Oracle recommends to start building new Oracle .NET applications with Oracle Data Provider for .NET (ODP.NET) and migrate existing applications to ODP.NET.

http://www.oracle.com/technetwork/topics/dotnet/index-085703.html

Deep
  • 1,025
  • 11
  • 7