📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

You join a team whose main .NET solution builds with about 5,000 compiler and analyser warnings, and nobody reads them any more. You're asked to make static analysis useful again without stopping feature delivery. Walk me through what you would do in the first weeks and how you would keep it from sliding back.

Covers a real rollout plan for analysers on a legacy .NET solution with thousands of warnings: measuring and grouping warnings, deciding per rule (fix, enforce, or switch off), mechanical bulk fixes, a ratchet so the count can only fall, per-project warnings-as-errors, team agreement and progress tracking.

Senior RealWorldScenario Advanced code-quality legacy-code roslyn-analyzers static-analysis technical-debt treat-warnings-as-errors

🎯 Key points

  • Measure first: binary log (dotnet build -bl) or a warnings-only file log, grouped by diagnostic id and project; usually 10 ids make 80% of the count
  • Prioritise rules by risk, not count: what has caused incidents, which rules guard money, data and resources (CS8602, CA2000, CA2100), and how critical the code is
  • Decide the buckets together with the team in a short working session: enforce, auto-fix (IDE style) or switch off in .editorconfig with a reason; record it in an ADR so buy-in survives turnover
  • Stop the bleeding early, but only for agreed rules: rules already at zero become errors (no existing code breaks), and new projects get TreatWarningsAsErrors
  • Ratchet: CI fails if the warning count rises above a committed baseline; the baseline only moves down
  • Bulk mechanical fixes with dotnet format / IDE fix-all in separate, behaviour-free PRs, listed in .git-blame-ignore-revs
  • Risky warnings (nullable, disposal, async) fixed by area with tests, boy-scout style plus a small sprint budget agreed with the product owner, never a big-bang clean-up or mass GlobalSuppressions / NoWarn
  • Communicate the trend weekly, explain why each enforced rule matters (especially for newer developers), and celebrate projects that reach zero

⏱ 30-second answer

I wouldn't try to fix 5,000 warnings. I'd measure, stop new ones, then pay down by value.

  • Measure: a binary log grouped by diagnostic id and project; usually ten ids are 80% of the count.
  • Decide per rule with the team: enforce the ones that are real bugs (CS8602, CA2000, CA2100), auto-fix the style ones, and switch off the noise in .editorconfig, recorded in an ADR.
  • Stop the bleeding: rules already at zero become errors; a CI ratchet fails the build if the count rises above a committed baseline, which only moves down.
  • Pay down: mechanical dotnet format PRs with no behaviour change; risky fixes (nullability, disposal) area by area with tests, boy-scout style.

Trade-off: the ratchet is slower than a clean-up sprint, but it never blocks delivery and the count can only go one way.

🗣 Full answer (senior)

How I would answer this in an interview

"The first thing I'd say is that 5,000 warnings isn't a code problem, it's a signal problem: the team can't see the one warning that matters. So the goal isn't zero, it's making a new warning visible again, and then paying down the old ones by value.

For example, at [company] the [order platform] solution had about [5,200] warnings across [40] projects. In week one I took a binary log of the CI build and grouped the warnings by id and project. [Eleven] ids made up [83%]: mostly CS8602 and friends from a half-finished nullable rollout, CA2007 ConfigureAwait, and a few hundred IDE style rules. I booked an hour with the team and we went through the top ids together. We agreed three buckets: rules that find real bugs, which we'd enforce; style rules we'd fix automatically with dotnet format; and rules we decided we didn't care about, like CA2007 in an ASP.NET Core app, which we switched off in .editorconfig with the reason in an ADR. That alone took the count to about [2,900] without changing a line of code. Then I stopped the bleeding: every rule that was already at zero became an error, and I added a ratchet step to CI that compares the warning count with a baseline file in the repo and fails if it goes up. When a PR lowers it, the developer lowers the baseline in the same PR. The mechanical fixes went in as separate, behaviour-free PRs added to .git-blame-ignore-revs. Nullable and disposal warnings were fixed area by area with tests, as part of feature work in those areas plus [10%] of each sprint.

The result was [5,200] to [under 300] in [four] months, [18] projects at zero with TreatWarningsAsErrors on, and we found [two] real connection leaks along the way. The mistake I see is the opposite approach: a GlobalSuppressions.cs with 5,000 entries, or NoWarn everywhere, so the dashboard is green and the debt is invisible."


The plan by week

When Action Outcome
Week 1 Binary log, group by id and project; top ids reviewed with the team Shared picture, agreed rule buckets
Week 1 ADR: which rules are enforced, auto-fixed, switched off A decision people can find later
Week 2 Switch off agreed noise in .editorconfig; zero-count rules to error; CI ratchet Count drops, can't rise
Weeks 2–4 dotnet format / fix-all PRs per rule, behaviour-free Style warnings gone
Ongoing Risky fixes by area with tests; projects at zero switch to TreatWarningsAsErrors Steady decline, real bugs found

Deciding per rule

Bucket Examples Action
Real bug risk CS8602, CA2000, CA2100, CA1849, CA2016 Enforce; fix with tests
Mechanical style IDE0005, IDE0161, IDE0090 dotnet format, then enforce
Not valuable here CA2007 in an ASP.NET Core app, CA1062 with nullable on Switch off with reason
Unsure CA1031 catch general exception Leave as warning, revisit

Production example

In that rollout the ratchet failed [about 15] PRs in the first month, each fixed in minutes because the new warning was in the PR's own code. Build output went from [5,200] lines of warnings to [a screenful], and the team started treating a new warning as a review comment rather than background noise.

🔍 What the interviewer is checking

Checks whether the candidate can lead a pragmatic, incremental quality improvement on a legacy codebase: measuring, deciding with the team, enforcing without blocking delivery, and sustaining the result.

Green flags

  • Measures and groups by rule before acting
  • Separates real-bug rules from style and noise, records decisions
  • Stops new warnings first (ratchet, errors for clean rules)
  • Behaviour-free bulk PRs; risky fixes with tests
  • Involves the team and reports progress in risk terms

Red flags

  • 'Turn on warnings as errors and fix everything'
  • Mass suppressions or NoWarn to get to green
  • Big-bang clean-up sprint with no tests
  • No plan to keep it from sliding back

📚 Learn in depth

1. Why warnings stop working

A warning is useful only if a human notices it at the moment it is introduced. Past a few dozen, new warnings are invisible: the cost of attention is too high, so everyone ignores the whole list. This is the same mechanism as alert fatigue in operations.

  warnings visible to a developer
      │
   10 ┤ ●  every new one noticed
  100 ┤    ●  skimmed
 1000 ┤         ●  ignored
 5000 ┤               ●  'the build always says that'
      └──────────────────────────── time

2. Measuring

  • dotnet build -bl:build.binlog and open it in the MSBuild Structured Log Viewer; the warnings view groups by code and project.
  • Or a warnings-only file logger: -flp:"logfile=warnings.log;warningsonly", then group by the CSxxxx/CAxxxx/IDExxxx code.
  • Deduplicate: multi-targeted projects and incremental builds report the same warning more than once.
  • Run on a clean CI build, not a developer's incremental build, or the count changes between runs.

3. How configuration layers work

AnalysisLevel / AnalysisMode (Directory.Build.props) ──► which rules are on by default
          ▼
.editorconfig / .globalconfig  dotnet_diagnostic.<id>.severity ──► per-rule override
          ▼
WarningsAsErrors / TreatWarningsAsErrors / NoWarn (MSBuild) ──► how warnings affect the build
          ▼
#pragma / [SuppressMessage] ──► single occurrence, with justification

Use .editorconfig for per-rule decisions (scoped by folder if needed, e.g. stricter in src/Domain/), WarningsAsErrors for specific ids, and TreatWarningsAsErrors only per project once that project is at zero.

4. The ratchet

A ratchet allows movement in one direction. The CI step counts unique warnings and compares with a committed warnings-baseline.txt. Higher: fail. Lower: pass, and ask the author to lower the baseline. It needs no tooling licence and works with any analyser. SonarQube's new-code gate is a richer version of the same idea.

5. Safe bulk fixes

  • dotnet format style --diagnostics IDE0005 IDE0161 and dotnet format analyzers --diagnostics CA1822 apply code fixes in bulk.
  • One rule per PR, no behaviour changes, reviewed by skimming; record the commit in .git-blame-ignore-revs so git blame stays useful.
  • Nullable warnings are not mechanical: each ! is a claim. Fix them with tests, or enable nullable per folder/file (#nullable enable) as each area is cleaned.

6. People

The technical plan is the easy half. Agree buckets with the team, publish the trend, and make each project reaching zero a visible milestone. A rule imposed without agreement gets #pragma warning disable within a week.

Try it yourself

  1. Take a binlog of a real solution and list the top ten warning ids by count.
  2. Write the ratchet script below into a pipeline and confirm a new warning fails it.
  3. Run dotnet format style --verify-no-changes and then apply one rule in a single PR.
  4. Add a .git-blame-ignore-revs file and configure git config blame.ignoreRevsFile.
  5. Pick one project, get it to zero, enable TreatWarningsAsErrors, and measure how long it stays green.

💻 Code

Build settings that stop new problems without breaking the existing build.

<!-- Directory.Build.props -->
<Project>
  <PropertyGroup>
    <AnalysisLevel>10.0-recommended</AnalysisLevel>   <!-- pinned: SDK upgrades don't move the bar -->
    <EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
    <!-- Rules already at zero: any new occurrence fails the build -->
    <WarningsAsErrors>$(WarningsAsErrors);CA2000;CA2100;CA2016;CS8600;CS8602;CS8604</WarningsAsErrors>
  </PropertyGroup>
  <!-- Projects that reached zero opt in to the strict mode -->
  <PropertyGroup Condition="'$(StrictWarnings)' == 'true'">
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
  </PropertyGroup>
</Project>
# .editorconfig: decisions from ADR-0031 (analyser rollout)
root = true

[*.cs]
# Not valuable in ASP.NET Core apps (no SynchronizationContext)
dotnet_diagnostic.CA2007.severity = none
# Redundant once nullable is on in a project
dotnet_diagnostic.CA1062.severity = none
# Mechanical: fixed by dotnet format, then enforced
dotnet_diagnostic.IDE0005.severity = warning

[src/Billing.Domain/**.cs]
# Stricter where the money is
dotnet_diagnostic.CA1305.severity = error
#!/usr/bin/env bash
# ci/warnings-ratchet.sh: fail if the warning count rises above the committed baseline
set -euo pipefail
dotnet build Orders.slnx -c Release --no-incremental \
  -flp:"logfile=warnings.log;warningsonly" > /dev/null
# Unique warnings (multi-targeting reports duplicates)
count=$(grep -E 'warning (CS|CA|IDE|SA|S)[0-9]+' warnings.log | sort -u | wc -l)
baseline=$(cat warnings-baseline.txt)
echo "Warnings: $count (baseline $baseline)"
if (( count > baseline )); then
  echo "New warnings introduced. Top ids:"
  grep -oE 'warning (CS|CA|IDE|SA|S)[0-9]+' warnings.log | sort | uniq -c | sort -rn | head
  exit 1
elif (( count < baseline )); then
  echo "Nice: please lower warnings-baseline.txt to $count in this PR."
fi

A behaviour-free fix PR, before and after:

// Before: CS8602 + CA2000 in OrderExporter
public string Export(Order order)
{
    var writer = new StringWriter();
    writer.Write(order.Customer.Name);      // Customer may be null
    return writer.ToString();
}

// After: fixed with a test for the null-customer case
public string Export(Order order)
{
    using var writer = new StringWriter(CultureInfo.InvariantCulture);
    writer.Write(order.Customer?.Name ?? "(guest)");
    return writer.ToString();
}

⚠ Common mistakes

  • Mistake: A clean-up sprint to reach zero. Why it is wrong: it stops delivery, fixes low-value warnings first and the count creeps back. Instead: stop new warnings, then pay down by value.
  • Mistake: Turning on TreatWarningsAsErrors for the whole solution on day one. Why it is wrong: nothing builds, so it gets reverted or NoWarn grows. Instead: errors for zero-count rules, and per project once at zero.
  • Mistake: Generating a GlobalSuppressions.cs with thousands of entries. Why it is wrong: the debt becomes invisible and future occurrences in those members are hidden too. Instead: a ratchet baseline that only goes down.
  • Mistake: Silencing nullable warnings with !. Why it is wrong: each ! is an untested claim that can become a NullReferenceException. Instead: fix the flow, add tests, enable nullable per area.
  • Mistake: Mixing bulk formatting with behaviour changes. Why it is wrong: reviewers can't see the real change and blame history is ruined. Instead: one rule per PR, no behaviour change, add to .git-blame-ignore-revs.
  • Mistake: Deciding the rule set alone. Why it is wrong: the team suppresses rules they don't believe in. Instead: agree buckets together and record them in an ADR.
  • Mistake: Leaving AnalysisLevel unpinned. Why it is wrong: an SDK upgrade adds new rules and breaks the ratchet overnight. Instead: pin it and raise it deliberately.
  • Mistake: Counting warnings from incremental local builds. Why it is wrong: unchanged projects don't re-report. Instead: count on a clean CI build.

🏛 Senior insight: trade-offs

The senior move is to reframe the goal from 'zero warnings' to 'every new warning is seen', because that can be achieved in a week and the rest becomes routine. The drop from thousands to a few thousand by switching off noise looks free, but it only works because the team made those decisions together: that session is where buy-in comes from, and it also levels knowledge. Newer developers often can't tell which warnings matter, while experienced ones have learned to ignore all of them; walking through the top ids together, with a real incident as the example, fixes both.

Prioritise by risk. I rank rules by what they protect: anything linked to a past incident, rules guarding money, personal data, resources and security first; style last. Critical modules (billing, auth) get stricter severities via folder-scoped .editorconfig sections. Making zero-count rules errors is safe because no existing code breaks, but I still announce it and explain each rule so the first failed PR isn't a surprise.

I choose mechanisms that can't be quietly undone (a ratchet in CI, errors for clean rules, TreatWarningsAsErrors per project as each reaches zero), agree a small sprint budget with the product owner, and report progress in terms of risk found (e.g. connection leaks, null crashes avoided), not warnings fixed.

Option When it fits Cost When not to
Ratchet on warning count Any legacy solution, no extra tooling A script and a baseline file When the count is already near zero (just use errors)
SonarQube new-code gate Already using Sonar, want per-line attribution Licence for PR analysis Only to replace build errors for clean rules
TreatWarningsAsErrors everywhere New or clean solutions Blocks on any warning, including SDK upgrades Legacy code with thousands of warnings
Mass suppression file Almost never; maybe a generated code folder Hides debt Hand-written code
Clean-up sprint Small solution, a few hundred mechanical warnings One sprint of no features Thousands of warnings or risky fixes

🔗 Follow-ups the interviewer may ask

  1. When: Candidate mentions TreatWarningsAsErrors or NoWarn Why: Checks they know how to use warnings-as-errors well rather than blanket settings
    How to answer

    The file under review turns on TreatWarningsAsErrors and then hides 25 warnings with NoWarn. That list includes nullable warnings, obsolete-API warnings and a security rule, so the policy looks strict while silencing the warnings that matter most. I'd remove those suppressions. Rules that genuinely don't apply would get a severity in .editorconfig, scoped to the right folders and commented. Rules we can't fix yet would go in WarningsNotAsErrors, so they stay visible as warnings. I'd also pin AnalysisLevel so an SDK upgrade can't break the build overnight, apply the same settings locally and in CI, and ratchet a legacy codebase towards zero warnings rather than flipping everything at once.

  2. When: Candidate says most warnings are nullable warnings Why: Checks they can run a nullable rollout without stopping feature work
    How to answer

    <Nullable>enable</Nullable> makes reference types non-nullable by default: string? means a value can be null and string means it can't. The compiler then warns when code might dereference null. It's purely compile-time, so nothing changes at run time. In a big codebase I migrate bottom-up: shared libraries and domain types first, because their annotations flow out to everyone else. I go project by project, or file by file with #nullable enable, and give each step a small pull request so feature work carries on. When a project is clean I make its nullable warnings errors with WarningsAsErrors=nullable, so it can't slip back. I use attributes such as [NotNullWhen] where flow analysis needs help and keep ! for real boundaries. I also watch for two things: EF Core migrations, where nullability decides whether columns are required, and public APIs, where annotations are part of the contract.

  3. When: Candidate mentions a sprint budget or the product owner Why: Checks how they prioritise and negotiate time for technical debt
    How to answer

    Technical debt is the future cost of a shortcut, and the interest is the extra effort or risk it adds every time we work near it. I make it visible in a debt register with each item's impact, how often we pay its interest (change frequency, incidents, delays) and a rough cost to fix. I prioritise by interest, not by how ugly the code is: debt in a hotspot that slows every feature beats a messy module nobody touches. I get time by explaining it in business terms (lead time, incident risk, cost), by reserving a steady share of capacity, and by pairing debt fixes with features that touch the same area.

🛠 Real-world problems: how you handle them

5,200 warnings to under 300 with a CI ratchet
Situation
An [order management] solution of [40] projects and roughly [600k] lines, [3] teams shipping weekly. The CI build printed about [5,200] warnings; a connection-pool exhaustion incident the month before had been flagged by `CA2000` a year earlier but nobody saw it.
Signals
Build logs thousands of lines long; reviewers never mentioning warnings; nullable half-enabled; a postmortem action item 'make analysers useful'.
Investigation
Binary log of a clean CI build in the MSBuild Structured Log Viewer, grouped by id and project; top [11] ids were [83%] of the count; checked the incident's warning history in git blame; one-hour team session to bucket rules.
Resolution
Immediately: switched off agreed noise (`CA2007`, `CA1062`) in `.editorconfig`, made zero-count and real-bug rules errors where already clean, added the warnings ratchet to the PR pipeline. Then: `dotnet format` PRs per style rule; nullable and disposal fixes area by area with tests and [10%] sprint budget; projects at zero switched to `TreatWarningsAsErrors`.
Prevention
ADR for the rule buckets; pinned `AnalysisLevel`; ratchet and baseline in the repo; weekly trend in the team channel; new projects created with `StrictWarnings=true`.

How to tell it (STAR)

**S:** At [company] our main solution printed about [5,200] warnings and a connection leak that `CA2000` had flagged a year earlier had just caused an outage. **T:** I was asked to make analysers useful again without pausing feature work. **A:** I grouped the warnings by rule, agreed with the team which to enforce, auto-fix or switch off, added a CI ratchet so the count couldn't rise, made clean rules errors, and paid down the risky ones area by area with tests. **R:** In [four] months we went from [5,200] to [under 300], [18] projects run with warnings as errors, and we found [two] more real connection leaks before they reached production.

↩ Usually asked after

More in Static Analysis

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me