SECURITY WARNING: Never run commands you don't understand. Always review code before execution. Use at your own risk.
C# 12 errors

.NET & C# Errors

NuGet restore, null references, EF Core migrations, async deadlocks and Blazor interop.

Understanding C# errors

C# errors divide into compile-time and restore-time problems (NuGet resolution, target framework mismatches) and runtime problems dominated by null references and async misuse. The classic .NET production hazard is the sync-over-async deadlock, calling .Result or .Wait() on a task in a context with a synchronisation context, which manifests as a hang rather than an exception and is therefore much harder to spot.

How to debug C# errors

  1. Run dotnet restore --verbosity detailed to see which feed each package resolved from. Most restore failures are a private feed with expired credentials, not a missing package.
  2. Enable nullable reference types (<Nullable>enable</Nullable>) and treat the warnings as errors. This converts a whole class of production NullReferenceExceptions into compile failures.
  3. For async hangs, search the codebase for .Result, .Wait() and .GetAwaiter().GetResult(). Replace with await all the way up, or use ConfigureAwait(false) in library code.
  4. For EF Core, run dotnet ef migrations list to see which migrations the database believes are applied before generating a new one.
  5. Capture a dump with dotnet-dump and inspect it with dotnet-gcdump / dotnet-counters when the process misbehaves without throwing.

Tools worth reaching for

  • dotnet restore -v detailed
  • dotnet ef migrations list
  • dotnet-counters
  • dotnet-dump

All 12 C# errors

Other categories