views:

1160

answers:

2

I have VB.Net code in VS 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.

+3  A: 

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

However, the "don't use obsolete apis" warning is not coming from CA, 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.

Martin Peck
I don't have that option, for some reason. Thought about adding that info too late :(
Updated my answer - this is not a CA warning (is it?)
Martin Peck
@Martin, your correct, it's a compiler warning.
JaredPar
+5  A: 

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
Note that this will get rid of _all_ obsolete warnings in your project, not just this one instance...
bdukes