Filter
Exclude
Time range
-
Near
๐—ฆ๐—ฒ๐—ฐ๐—ฟ๐—ฒ๐˜: ๐—›๐—ผ๐˜„ ๐˜๐—ผ ๐—ฒ๐—น๐—ถ๐—บ๐—ถ๐—ป๐—ฎ๐˜๐—ฒ ๐Ÿต๐Ÿต% ๐—ผ๐—ณ ๐—ก๐˜‚๐—น๐—น๐—ฅ๐—ฒ๐—ณ๐—ฒ๐—ฟ๐—ฒ๐—ป๐—ฐ๐—ฒ๐—˜๐˜…๐—ฐ๐—ฒ๐—ฝ๐˜๐—ถ๐—ผ๐—ป๐˜€ Few developers know about this. But it can completely change how you write C# code. ๐—ก๐˜‚๐—น๐—น๐—ฅ๐—ฒ๐—ณ๐—ฒ๐—ฟ๐—ฒ๐—ป๐—ฐ๐—ฒ๐—˜๐˜…๐—ฐ๐—ฒ๐—ฝ๐˜๐—ถ๐—ผ๐—ป is the most common runtime error in .NET projects. And it usually happens at the worst possible time โ€” during production. Most developers fix NullReferenceExceptions after they happen. Smart developers prevent them from happening at all. You can eliminate almost all of them with two simple project settings. Add these to your .csproj file: <๐™ฟ๐š›๐š˜๐š™๐šŽ๐š›๐š๐šข๐™ถ๐š›๐š˜๐šž๐š™> <๐™ฝ๐šž๐š•๐š•๐šŠ๐š‹๐š•๐šŽ>๐šŽ๐š—๐šŠ๐š‹๐š•๐šŽ</๐™ฝ๐šž๐š•๐š•๐šŠ๐š‹๐š•๐šŽ> <๐šƒ๐š›๐šŽ๐šŠ๐š๐š†๐šŠ๐š›๐š—๐š’๐š—๐š๐šœ๐™ฐ๐šœ๐™ด๐š›๐š›๐š˜๐š›๐šœ>๐š๐š›๐šž๐šŽ</๐šƒ๐š›๐šŽ๐šŠ๐š๐š†๐šŠ๐š›๐š—๐š’๐š—๐š๐šœ๐™ฐ๐šœ๐™ด๐š›๐š›๐š˜๐š›๐šœ> </๐™ฟ๐š›๐š˜๐š™๐šŽ๐š›๐š๐šข๐™ถ๐š›๐š˜๐šž๐š™> ๐—›๐—ผ๐˜„ ๐—œ๐˜ ๐—ช๐—ผ๐—ฟ๐—ธ๐˜€: ๐Ÿ“Œ Nullable enables C#'s null-reference static analysis: โ†ณ Warns about potential null reference issues โ†ณ Forces explicit handling of nullable types โ†ณ Makes null safety visible in your code ๐Ÿ“Œ TreatWarningsAsErrors turns warnings into build failures: โ†ณ Code won't compile until null issues are fixed (and any other issues) โ†ณ Catches problems during development, not production ๐—ฃ๐—ฟ๐—ผ ๐˜๐—ถ๐—ฝ: ๐Ÿ“Œ You can add these settings to the Directory(.)Build(.)props file (near sln file) and they will be applied to all the projects in the solution. Together, these two settings push null problems from runtime โ†’ compile time. That's how you eliminate 99% of NullReferenceExceptions in your projects. It's one of the highest ROI settings you can enable in .NET. โ–ถ๏ธ Next time you start a project, make this your first step. ๐Ÿ‘‰ Have you already enabled nullable reference types in your projects, or are you still relying on runtime checks? โ€” โ™ป๏ธ Repost to help others eliminate NullReferenceExceptions โž• Follow me ( @AntonMartyniuk ) to improve your .NET Skills
3
15
93
3,363
๐—ฆ๐—ฒ๐—ฐ๐—ฟ๐—ฒ๐˜: ๐—›๐—ผ๐˜„ ๐˜๐—ผ ๐—ฒ๐—น๐—ถ๐—บ๐—ถ๐—ป๐—ฎ๐˜๐—ฒ ๐Ÿต๐Ÿต% ๐—ผ๐—ณ ๐—ก๐˜‚๐—น๐—น๐—ฅ๐—ฒ๐—ณ๐—ฒ๐—ฟ๐—ฒ๐—ป๐—ฐ๐—ฒ๐—˜๐˜…๐—ฐ๐—ฒ๐—ฝ๐˜๐—ถ๐—ผ๐—ป๐˜€ Few developers know about this. But it can completely change how you write C# code. ๐—ก๐˜‚๐—น๐—น๐—ฅ๐—ฒ๐—ณ๐—ฒ๐—ฟ๐—ฒ๐—ป๐—ฐ๐—ฒ๐—˜๐˜…๐—ฐ๐—ฒ๐—ฝ๐˜๐—ถ๐—ผ๐—ป is the most common runtime error in .NET projects. And it usually happens at the worst possible time โ€” during production. Most developers fix NullReferenceExceptions after they happen. Smart developers prevent them from happening at all. You can eliminate almost all of them with two simple project settings. Add these to your .csproj file: <๐™ฟ๐š›๐š˜๐š™๐šŽ๐š›๐š๐šข๐™ถ๐š›๐š˜๐šž๐š™> <๐™ฝ๐šž๐š•๐š•๐šŠ๐š‹๐š•๐šŽ>๐šŽ๐š—๐šŠ๐š‹๐š•๐šŽ</๐™ฝ๐šž๐š•๐š•๐šŠ๐š‹๐š•๐šŽ> <๐šƒ๐š›๐šŽ๐šŠ๐š๐š†๐šŠ๐š›๐š—๐š’๐š—๐š๐šœ๐™ฐ๐šœ๐™ด๐š›๐š›๐š˜๐š›๐šœ>๐š๐š›๐šž๐šŽ</๐šƒ๐š›๐šŽ๐šŠ๐š๐š†๐šŠ๐š›๐š—๐š’๐š—๐š๐šœ๐™ฐ๐šœ๐™ด๐š›๐š›๐š˜๐š›๐šœ> </๐™ฟ๐š›๐š˜๐š™๐šŽ๐š›๐š๐šข๐™ถ๐š›๐š˜๐šž๐š™> ๐—›๐—ผ๐˜„ ๐—œ๐˜ ๐—ช๐—ผ๐—ฟ๐—ธ๐˜€: ๐Ÿ“Œ Nullable enables C#'s null-reference static analysis: โ†ณ Warns about potential null reference issues โ†ณ Forces explicit handling of nullable types โ†ณ Makes null safety visible in your code ๐Ÿ“Œ TreatWarningsAsErrors turns warnings into build failures: โ†ณ Code won't compile until null issues are fixed (and any other issues) โ†ณ Catches problems during development, not production ๐—ฃ๐—ฟ๐—ผ ๐˜๐—ถ๐—ฝ: ๐Ÿ“Œ You can add these settings to the Directory(.)Build(.)props file (near sln file) and they will be applied to all the projects in the solution. Together, these two settings push null problems from runtime โ†’ compile time. That's how you eliminate 99% of NullReferenceExceptions in your projects. It's one of the highest ROI settings you can enable in .NET. โ–ถ๏ธ Next time you start a project, make this your first step. ๐Ÿ‘‰ Have you already enabled nullable reference types in your projects, or are you still relying on runtime checks? โ€” โ™ป๏ธ Repost to help others eliminate NullReferenceExceptions โž• Follow me ( @AntonMartyniuk ) to improve your .NET Skills
7
19
114
4,318
I've seen more staging deployments crash from empty databases than from actual bugs. Your schema is perfect. Your migrations ran. But the roles table? Empty. Default categories? Gone. Admin account? Doesn't exist. Here are 7 things I learned about data seeding in EF Core 10 after debugging this in 5 projects ๐Ÿ‘‡ ๐Ÿญ. ๐—˜๐—บ๐—ฝ๐˜๐˜† ๐—ฑ๐—ฎ๐˜๐—ฎ๐—ฏ๐—ฎ๐˜€๐—ฒ = ๐—ฏ๐—ฟ๐—ผ๐—ธ๐—ฒ๐—ป ๐—ฑ๐—ฎ๐˜๐—ฎ๐—ฏ๐—ฎ๐˜€๐—ฒ Your app expects certain data to exist. When it doesn't, you get cryptic NullReferenceExceptions that look like code bugs but are actually missing seed data. ๐Ÿฎ. ๐—›๐—ฎ๐˜€๐——๐—ฎ๐˜๐—ฎ ๐—ถ๐˜€ ๐—ณ๐—ผ๐—ฟ ๐—ฟ๐—ฒ๐—ณ๐—ฒ๐—ฟ๐—ฒ๐—ป๐—ฐ๐—ฒ ๐—ฑ๐—ฎ๐˜๐—ฎ ๐—ผ๐—ป๐—น๐˜† Roles, status codes, country lists. Data that should exist in every environment. It bakes INSERT statements into your migration files. ๐Ÿฏ. ๐—™๐—ถ๐˜…๐—ฒ๐—ฑ ๐—š๐—จ๐—œ๐——๐˜€ ๐—ฎ๐—ฟ๐—ฒ ๐—ป๐—ผ๐—ป-๐—ป๐—ฒ๐—ด๐—ผ๐˜๐—ถ๐—ฎ๐—ฏ๐—น๐—ฒ ๐˜„๐—ถ๐˜๐—ต ๐—›๐—ฎ๐˜€๐——๐—ฎ๐˜๐—ฎ If you let Guid.NewGuid() run, every migration sees "new" data and generates DELETE INSERT. Fixed GUIDs tell EF Core "same record." ๐Ÿฐ. ๐—จ๐˜€๐—ฒ๐—ฆ๐—ฒ๐—ฒ๐—ฑ๐—ถ๐—ป๐—ด ๐—ถ๐˜€ ๐˜๐—ต๐—ฒ ๐—ป๐—ฒ๐˜„ ๐—ฑ๐—ฒ๐—ณ๐—ฎ๐˜‚๐—น๐˜ Introduced in EF Core 9, UseSeeding/UseAsyncSeeding runs at startup. It respects your DDD patterns, calls factory methods, and doesn't bloat migrations. ๐Ÿฑ. ๐—”๐—น๐˜„๐—ฎ๐˜†๐˜€ ๐—ถ๐—บ๐—ฝ๐—น๐—ฒ๐—บ๐—ฒ๐—ป๐˜ ๐—ฏ๐—ผ๐˜๐—ต ๐—ฐ๐—ฎ๐—น๐—น๐—ฏ๐—ฎ๐—ฐ๐—ธ๐˜€ UseSeeding (sync) AND UseAsyncSeeding (async). If you only implement async and some code path calls EnsureCreated (sync), no seeding happens. Silently. I've debugged this exact issue in production. ๐Ÿฒ. ๐—ฆ๐—ฒ๐—ฒ๐—ฑ ๐—ฝ๐—ฎ๐—ฟ๐—ฒ๐—ป๐˜๐˜€ ๐—ฏ๐—ฒ๐—ณ๐—ผ๐—ฟ๐—ฒ ๐—ฐ๐—ต๐—ถ๐—น๐—ฑ๐—ฟ๐—ฒ๐—ป With FK relationships, save parents first with a separate SaveChanges, then seed children. Combining everything into one SaveChanges can trigger FK violations. ๐Ÿณ. ๐——๐—ถ๐—ณ๐—ณ๐—ฒ๐—ฟ๐—ฒ๐—ป๐˜ ๐—ฑ๐—ฎ๐˜๐—ฎ ๐—ณ๐—ผ๐—ฟ ๐—ฑ๐—ถ๐—ณ๐—ณ๐—ฒ๐—ฟ๐—ฒ๐—ป๐˜ ๐—ฒ๐—ป๐˜ƒ๐—ถ๐—ฟ๐—ผ๐—ป๐—บ๐—ฒ๐—ป๐˜๐˜€ Development needs 50 records for pagination testing. Production needs only essential reference data. Use IHostEnvironment in Program.cs seeding. My default: start with UseSeeding. It covers 80% of scenarios. Reserve HasData for schema-level reference data. Read the entire article: codewithmukesh.com/blog/seedโ€ฆ
1
6
33
1,476
A subtle, yet powerful addition in C# 14: (that will reduce null reference exceptions) Null-conditional assignment. This operator allows you to assign a value to a member or element only if the object you're accessing is not null. It's a small change, but it can have a significant impact on code readability and safety. Why it's useful: - Eliminates repetitive null checks before assignments. - Simplifies code, making it easier to understand. - Safely skips assignments when the target object is null, avoiding NullReferenceExceptions. See the code example below.
3
10
42
2,153
๐—ฆ๐—ฒ๐—ฐ๐—ฟ๐—ฒ๐˜: ๐—›๐—ผ๐˜„ ๐˜๐—ผ ๐—ฒ๐—น๐—ถ๐—บ๐—ถ๐—ป๐—ฎ๐˜๐—ฒ ๐Ÿต๐Ÿต% ๐—ผ๐—ณ ๐—ก๐˜‚๐—น๐—น๐—ฅ๐—ฒ๐—ณ๐—ฒ๐—ฟ๐—ฒ๐—ป๐—ฐ๐—ฒ๐—˜๐˜…๐—ฐ๐—ฒ๐—ฝ๐˜๐—ถ๐—ผ๐—ป๐˜€ Few developers know about this. But it can completely change how you write C# code. ๐—ก๐˜‚๐—น๐—น๐—ฅ๐—ฒ๐—ณ๐—ฒ๐—ฟ๐—ฒ๐—ป๐—ฐ๐—ฒ๐—˜๐˜…๐—ฐ๐—ฒ๐—ฝ๐˜๐—ถ๐—ผ๐—ป is the most common runtime error in .NET projects. And it usually happens at the worst possible time โ€” during production. Most developers fix NullReferenceExceptions after they happen. Smart developers prevent them from happening at all. You can eliminate almost all of them with two simple project settings. Add these to your .csproj file: <๐™ฟ๐š›๐š˜๐š™๐šŽ๐š›๐š๐šข๐™ถ๐š›๐š˜๐šž๐š™> <๐™ฝ๐šž๐š•๐š•๐šŠ๐š‹๐š•๐šŽ>๐šŽ๐š—๐šŠ๐š‹๐š•๐šŽ</๐™ฝ๐šž๐š•๐š•๐šŠ๐š‹๐š•๐šŽ> <๐šƒ๐š›๐šŽ๐šŠ๐š๐š†๐šŠ๐š›๐š—๐š’๐š—๐š๐šœ๐™ฐ๐šœ๐™ด๐š›๐š›๐š˜๐š›๐šœ>๐š๐š›๐šž๐šŽ</๐šƒ๐š›๐šŽ๐šŠ๐š๐š†๐šŠ๐š›๐š—๐š’๐š—๐š๐šœ๐™ฐ๐šœ๐™ด๐š›๐š›๐š˜๐š›๐šœ> </๐™ฟ๐š›๐š˜๐š™๐šŽ๐š›๐š๐šข๐™ถ๐š›๐š˜๐šž๐š™> ๐—›๐—ผ๐˜„ ๐—œ๐˜ ๐—ช๐—ผ๐—ฟ๐—ธ๐˜€: ๐Ÿ“Œ Nullable enables C#'s null-reference static analysis: โ†ณ Warns about potential null reference issues โ†ณ Forces explicit handling of nullable types โ†ณ Makes null safety visible in your code ๐Ÿ“Œ TreatWarningsAsErrors turns warnings into build failures: โ†ณ Code won't compile until null issues are fixed (and any other issues) โ†ณ Catches problems during development, not production ๐—ฃ๐—ฟ๐—ผ ๐˜๐—ถ๐—ฝ: ๐Ÿ“Œ You can add these settings to the Directory(.)Build(.)props file (near sln file) and they will be applied to all the projects in the solution. Together, these two settings push null problems from runtime โ†’ compile time. That's how you eliminate 99% of NullReferenceExceptions in your projects. It's one of the highest ROI settings you can enable in .NET. โ–ถ๏ธ Next time you start a project, make this your first step. ๐Ÿ‘‰ Have you already enabled nullable reference types in your projects, or are you still relying on runtime checks? โ€” โ™ป๏ธ Repost to help others eliminate NullReferenceExceptions โž• Follow me ( @AntonMartyniuk ) to improve your .NET Skills
11
29
210
11,344
A subtle, yet powerful addition in C# 14: (that will reduce null reference exceptions) Null-conditional assignment. This operator allows you to assign a value to a member or element only if the object you're accessing is not null. It's a small change, but it can have a significant impact on code readability and safety. Why it's useful: - Eliminates repetitive null checks before assignments. - Simplifies code, making it easier to understand. - Safely skips assignments when the target object is null, avoiding NullReferenceExceptions. See the code example below.
6
11
101
6,376
Replying to @kristijan_kralj
These 2 settings in csproj can eliminate 95% of all NullReferenceExceptions: - Nullable = true - TreatWarningsAsErrors = true
1
1
12
627
The outdated approach to handling "null" in C#: โ€ข Return null from methods and hope for the best โ€ข Add dozens of "if (x != null)" checks everywhere โ€ข Trust developers to "just know" what might be nullable All that hard work for what? Brittle code, hidden bugs, and NullReferenceExceptions? Here's the new path: โ€ข Return empty values instead of null (Enumerable.Empty<T>(), string.Empty, [], etc.) โ€ข Use C# nullable reference types to catch issues at compile time โ€ข Replace null checks with the Null Object pattern and the null-conditional (?.) operator Here's how to get started: โ€ข Turn on nullable reference types in your .csproj โ€ข Replace "null" return values with safe defaults โ€ข Refactor repeated "null" checks into safe wrappers or default behaviors Writing safer, crash-resistant C# code is hard. But hunting null reference exceptions in production is 100x harder.
8
6
75
5,991
10 Jul 2025
Replying to @elonmusk @grok
Grok's Performance in Code Assistance: A Critical Assessment Grok, the AI developed by xAI, demonstrated profound incompetence in providing C# .NET Core 8 WinForms code for a custom ComboBox in a DataGridView. The process, which should have taken minutes, dragged on for an excessive duration due to Grok's repeated failures to deliver functional code.Key shortcomings: Poor Programming Expertise: Grok's code was consistently buggy, plagued by issues like NullReferenceExceptions, AccessViolationExceptions, disappearing text, vanishing cursors, flickering dropdowns, and infinite loops. Basic WinForms behaviors, such as text preservation during filtering or stable dropdown opening, were mishandled, revealing a lack of depth in understanding .NET controls and event handling. Unnecessary Iterations: Over dozens of responses, Grok produced variant after variant, each "fix" introducing new bugs while failing to resolve core problems. Simple concepts like restoring text after list updates or using BindingList for smooth filtering were bungled, leading to code bloat from 50 lines to over 150, then back down, without stability. Extended Duration: What began as a straightforward request extended into a multi-day ordeal, wasting the user's time with compile errors, runtime crashes, and incomplete implementations. Grok's "continuous knowledge update" proved worthless, as solutions were trial-and-error hacks rather than informed expertise. User as Beta Tester: The user was forced into the role of unpaid beta tester, compiling and debugging Grok's flawed snippets, reporting issues like "text disappears again" or "dropdown closes immediately," while Grok iterated ineptly. This turned the interaction into a debugging session rather than efficient assistance. In summary, Grok is an unreliable tool for programming tasks, excelling only in generating frustration and inefficiency. xAI's claims of advanced AI capabilities are undermined by this display of mediocrity. Users deserve better; Grok falls short.
2
96
Blogged: Finalizers are tricker than you might think, Part 1. The post is very close to a 5 Why type of postmortem we use internally for the incidents where I cover an investigation of crashes caused by NullReferenceExceptions from the finalizers. #dotnet
3
5
27
1,782
29 May 2024
Debugging async exceptions just got easier with Visual Studio! ๐Ÿ› ๏ธ Now, it automatically breaks when an async Task method throws an exception, helping you identify issues faster. Say goodbye to frustrating NullReferenceExceptions and hello to improved productivity! #VisualStudio
3
9
490
My code's so OG powerful I get NullReferenceExceptions on non-nullable objects when nullables are enforced in C#.

ALT Sad Sponge Bob GIF by SpongeBob SquarePants

3
96
11 Aug 2023
Replying to @ddoomen
better protection from NullReferenceExceptions clearly stated intent (is null expected?) - some rough edge cases (especially with data initialization) - 3rd party libraries cannot be trusted We use it in our C# code but we strongly prefer how F# handles optional values.
3
5
391
Maximize code reliability and prevent dreaded #NullReferenceExceptions with #CSharp's nullable reference types! Declare variables with a '?' after the type to allow for optional values or assign null. #programming #dotnet #nullablereferencetypes
2
3
252
Say goodbye to NullReferenceExceptions with, the !N (Bang N) language that brings the power of C# without the headache of Nulls. #Programming #CSharp #BangN
3
6
1,399
Day 60 of #100daysofcode coding bug tracker. Debugging NullReferenceExceptions today. Great learning. Learned about tracing back null ref by using debug tool with breakpoints. Forced me to think about how it all works for sure. #100daysofcodingchallenge #learninpublic #dotnet
6
13
337
Bring Error Handling and Eliminate NullReferenceExceptions Using a Result Type inย .NET by Tobias Streng zpr.io/vS73G4MebaY7

1
1
19 Feb 2022
You can turn off nullable reference types by either globally in your csproj, or per file using the nullable preprocessor. Of course this doesn't stop NullReferenceExceptions from happening, you're just turning off the warning system.
4