Search code examples
c#winformsdebuggingwarningsanalysis

C# code analysis output on working project, warnings list advice requested


I recently finished the first part of a C# project, windows forms application, all works fine, it’s just when I run code analysis, (visual studio 2015), is throws up lots of warnings.

Questions:

  1. Why are these warnings not shown on normal debugging?

  2. Is it advisable to spend, (what would be a lot), of time solving these warnings? and why as the project works?

  3. If question 2 is true, is there a quick reference document, that can assist in the many warnings and there meanings?

I went through microsoft documentation, but very time comsuming.


Solution

    1. If by "code analysis" you mean the Error List window, which has three tabs for Errors, Warnings, and Messages, your program will indeed run if there are only Warnings and Messages, but there could be problems for you down the road. "Messages" are almost always stylistic suggestions (like a variable that VS thinks should be private, or an unused function), but Warnings are typically a sign that something COULD go wrong at runtime (such as neglecting to initialize a variable). The Error List window won't typically show up if there are no errors, but VS settings do control some of that behavior.
    2. How much time you should spend addressing the warnings depends on how much time you want to spend chasing runtime errors. I could care less about the "Messages", but my goal is always to have zero Warnings.
    3. I always just Google the Error or Warning ID, if the text description doesn't make any sense, and some Microsoft support site usually comes up... or even StackOverflow, with some good advice on how to fix it. You can suppress Warnings in code or VS settings, but that's only a last resort, if you realize you can't fix it, it's not an issue long-term, and you don't want to see it anymore.