C
C#•2y 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•2y 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.•2y ago
I suppose yes Though, the one shown is what the team prefers seeing
Doombox
Doombox•2y 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.•2y 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.•2y ago
it's called "Compiler Warning (level 2) CS0618". No idea what the category is
an.c.
an.c.•2y ago
IDE0079: Remove unnecessary suppression - .NET
Learn about code analysis rule IDE0079: Remove unnecessary suppression
an.c.
an.c.•2y ago
but those warning of the compiler don't really tell the category in the docs
Doombox
Doombox•2y 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.•2y ago
eh.......... I know I got very frustrated with this
Doombox
Doombox•2y 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.•2y ago
I started to think exactly that
Doombox
Doombox•2y ago
so I think you have no choice but to use pragmas when dealing with roslyn analyzer errors
an.c.
an.c.•2y ago
fair At least I know I did all I could thank you for looking into this Appreciated
Doombox
Doombox•2y 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.•2y ago
That's a good advice 😄 Thank you again
Accord
Accord•2y ago
✅ This post has been marked as answered!
Want results from more Discord servers?
Add your server
More Posts
How to write function in .net6? [Answered]I try .net6 for the first time and i got an error ask me to provide return value regardless that i aTimeSpan formatter [Answered]Hi, is there any function or library that would take an time length input, for example `5 min` or `3How do you pass into a method a generic after you've reflected? [Answered]Suppose I suspect that this IEnumerable (non-generic) is also an IReadOnlyList<T> where T : struct. Signalr not sending message(s) to specific user(s)in the hub i have setup this signature for a method ```cs public async Task SendMessage(string sendRider line problemI'd moved to rider but a line make me angry, anybody can help me about how can I remove this?Is it possible to publish a WPF Application into a single file with the font inside of the EXE?Is it possible to publish a WPF Application into a single file with the font inside of the EXE?Binding to Dictionary in WPF with a binding KEYhello i have a very specific problem related to WPF : i have a listbox with itemsSource <ListBox Itset default value of parameter to other parameter [Answered]ok, i am aware that this is probably not possible, but can i set default value of parameter x to vaChecking if an arbitrary (remote) URL is a file attachment, and extracting it if it is? [Answered]If I'm given an arbitrary URL (I don't have control over it), how can I check if it appears to be a How does assigning default values when creating an instance work? [Answered]I'm not sure how to ask this question. I also can't for the life of me remember what this style of i