C
C#•3y ago
an.c.

Suppress CS0618 for entire file [Answered]

Can I suppress CS0618 for an entire file? I tried with [System.Diagnostics.CodeAnalysis.SuppressMessage("Warning", "CS0618: Type or member is obsolete", Justification = "Some reason")] but it doesn't look correct. How can I achieve this? I want to avoid to #pragma warning disable CS0618 // Type or member is obsolete on each single occurrence. And I want to avoid a global setting.
16 Replies
Doombox
Doombox•3y ago
can't you #pragma warning disable {CODE} at the start of the file and then #pragma warning restore {CODE} at the end? I haven't done it in a while so I'm not certain
an.c.
an.c.OP•3y ago
I suppose yes Though, the one shown is what the team prefers seeing
Doombox
Doombox•3y ago
uhh not hugely familiar with with CodeAnalysis attributes but can't you create a global one on the assembly targeted at a specific type? I vaguely remember being able to target a namespace
an.c.
an.c.OP•3y ago
yes I can but the problem is the same, SuppressMessage uses strings for the category and I don't know what the category is. No clue how to find that from the documentation for CS0618
an.c.
an.c.OP•3y ago
it's called "Compiler Warning (level 2) CS0618". No idea what the category is
an.c.
an.c.OP•3y ago
IDE0079: Remove unnecessary suppression - .NET
Learn about code analysis rule IDE0079: Remove unnecessary suppression
an.c.
an.c.OP•3y ago
but those warning of the compiler don't really tell the category in the docs
Doombox
Doombox•3y ago
interesting, can't see the full name of the error anywhere though that seems to be the same for all CS errors
an.c.
an.c.OP•3y ago
eh.......... I know I got very frustrated with this
Doombox
Doombox•3y ago
aaaah, okay, so, I think that CA and CS are entirely different things the CS warning codes are from Roslyn and CA is legacy stuff
an.c.
an.c.OP•3y ago
I started to think exactly that
Doombox
Doombox•3y ago
so I think you have no choice but to use pragmas when dealing with roslyn analyzer errors
an.c.
an.c.OP•3y ago
fair At least I know I did all I could thank you for looking into this Appreciated
Doombox
Doombox•3y ago
no worries, just write a strongly worded email to management about using legacy analyzers and then carry on with your day pepelaff to /close when you're happy it's solved sunglas
an.c.
an.c.OP•3y ago
That's a good advice 😄 Thank you again
Accord
Accord•3y ago
✅ This post has been marked as answered!
Want results from more Discord servers?
Add your server