I'm looking for a way how to find a SuppressMessageAttribute catagory for a given warning (BC42015).
After recieving the following warning I would like to suppress it.
'SomeLib.SomeInterface.DrawRuler' is already implemented by the base class 'SomeLib.SomeClass'. Re-implementation of function assumed. C:\Project\somefile.vb 5 115 ALibName
Using the SuppressMessage attribute should work but how can I find the relevant Catagory. The following won't work.
<CodeAnalysis.SuppressMessageAttribute("IDUNNO","BC42015")>
All MSDN examples are pretty useless. In Source Suppression Overview
Rule Category - The category in which the rule is defined. For more information about code analysis rule categories, see some useless link.
As mentioned in Damien_The_Unbeliever's answer, the code analysis warnings are treated differently from compiler warnings. However, you may use a preprocessor directive (#Disable Warning
in VB, #pragma warning
in C#) to suppress this or other compiler warnings at a particular point in your code.
This example shows BC40003 being suppressed where class C2 implements sub1, which has already been implemented by base class C1:
Interface I1
Sub sub1(arg1 As Integer)
End Interface
Class C1
Implements I1
Public Sub sub1(arg1 As Integer) Implements I1.sub1
End Sub
End Class
Class C2
Inherits C1
Implements I1
#Disable Warning BC40003
Public Sub sub1(arg1 As Integer) Implements I1.sub1
#Enable Warning BC40003
End Sub
End Class
The general way to discover the category for a Code Analysis warning, for use in the SuppressMessageAttribute
attribute would be to consult the documentation for the warning.
For instance, for CA1039
, we get:
TypeName ListsAreStronglyTyped
CheckId CA1039
Category Microsoft.Design
Breaking Change Breaking
Now, for BC42015
we don't find such information. Why? Because it's not a code analysis warning. It's a compiler warning (note that we're in a completely different part of the MSDN library).
So far as I'm aware, there's no local way to override compiler warnings in VB - all you can do is disable the warning at the project level (but I'll admit, this is hardly ever what you want to do).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With