<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/c-nullable-reference-types-and-nullable-enable-explained-jjeifbksg" -->

---
title: C# Nullable Reference Types and #nullable enable Explained
description: C# nullable reference types are a compile-time check only: at runtime, string and string? are the same System.String, so null can still slip in. Enable them...
canonical: https://daily.dev/posts/c-nullable-reference-types-and-nullable-enable-explained-jjeifbksg
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: C# Nullable Reference Types and #nullable enable Explained | daily.dev
og:description: C# nullable reference types are a compile-time check only: at runtime, string and string? are the same System.String, so null can still slip in. Enable them...
og:url: https://daily.dev/posts/c-nullable-reference-types-and-nullable-enable-explained-jjeifbksg
og:image: https://api.daily.dev/og/posts/jjEifBksg.png
og:image:alt: C# Nullable Reference Types and #nullable enable Explained
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# C# Nullable Reference Types and #nullable enable Explained

**[Khalid Abuhakmeh](https://daily.dev/sources/khalidabuhakmeh)** · 8 min read · 0 upvotes · 0 comments

## Summary

C# nullable reference types are a compile-time check only: at runtime, string and string? are the same System.String, so null can still slip in. Enable them with <Nullable>enable</Nullable> in a .csproj or Directory.Build.props, or per file with #nullable enable. For CS8618, prefer required, a constructor or a default over null!. Attributes such as [NotNullWhen(true)] and [MemberNotNull] teach the compiler what your helpers guarantee. Null still gets through default structs, new string[10] arrays and JSON deserialization of missing properties, where required is what catches it.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://khalidabuhakmeh.com/posts/csharp-nullable-reference-types>

## Questions this post answers

### How do I fix CS8618 non-nullable property uninitialized in C# without using null!?

Avoid `= null!`, which only silences the warning while the property stays null. Instead, mark the property `required` so callers must set it in an object initializer, initialize it in a constructor, or give it a real default value. `required` is usually the right choice for DTOs and models, since the compiler then forces callers to supply the value.

_Developers cleaning up nullable warnings across a .NET codebase keep up with C# practices on daily.dev._

### Does #nullable enable prevent NullReferenceException at runtime in C#?

No. Nullable reference types are compile-time static flow analysis only; at runtime string and string? are both System.String. Reflection, JSON deserializers and unannotated third-party libraries can still put null into a variable declared non-nullable. Default structs and `new string[10]` arrays also hold nulls without any compiler warning.

_Anyone migrating a legacy .NET project to nullable annotations can follow C# nullability tips on daily.dev._

### Why does System.Text.Json leave a non-nullable string property null when the JSON property is missing?

A non-nullable property with no `required` modifier and no initializer is simply never set when the JSON omits it, so it stays null. Enabling RespectNullableAnnotations only makes an explicit null for a non-nullable property throw; it does not catch absent properties. Marking the property `required` makes the missing value throw during deserialization.

_Teams hardening API input handling in .NET can stay current on deserialization pitfalls through daily.dev._

## Similar posts on daily.dev

- [Correctly Check and Use Nullable Variables in C\#](https://daily.dev/posts/correctly-check-and-use-nullable-variables-in-c--cd8jjz6rq) · Atomic Spin · 11 upvotes · 0 comments
- [The best new features of C\# 14](https://daily.dev/posts/the-best-new-features-of-c-14-6gsbbjwv4) · InfoWorld · 46 upvotes · 4 comments
- [Model variable JSON field types with unions](https://daily.dev/posts/model-variable-json-field-types-with-unions-4ugh6mlue) · Damir's Corner · 6 upvotes · 0 comments

---

Tags: [#.net](https://daily.dev/tags/.net), [#c#](https://daily.dev/tags/c#)

[View this post on daily.dev](https://daily.dev/posts/c-nullable-reference-types-and-nullable-enable-explained-jjeifbksg)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"C# Nullable Reference Types and #nullable enable Explained","url":"https://daily.dev/posts/c-nullable-reference-types-and-nullable-enable-explained-jjeifbksg","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/c-nullable-reference-types-and-nullable-enable-explained-jjeifbksg"},"datePublished":"2026-11-27T19:54:49.688Z","dateModified":"2026-11-27T19:55:10.449Z","description":"C# nullable reference types are a compile-time check only: at runtime, string and string? are the same System.String, so null can still slip in. Enable them...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/c38f0c43a18d16baa1830dadf3229371?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/c38f0c43a18d16baa1830dadf3229371?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Khalid Abuhakmeh","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Khalid Abuhakmeh","logo":"https://media.daily.dev/image/upload/s--DwEMyeUp--/f_auto,q_auto/v1780213469/logos/khalidabuhakmeh?_a=BAMAMiWQ0","url":"https://daily.dev/sources/khalidabuhakmeh"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/c-nullable-reference-types-and-nullable-enable-explained-jjeifbksg","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":".net,c#","timeRequired":"PT8M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Khalid Abuhakmeh","item":"https://daily.dev/sources/khalidabuhakmeh"},{"@type":"ListItem","position":3,"name":"C# Nullable Reference Types and #nullable enable Explained"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/c-nullable-reference-types-and-nullable-enable-explained-jjeifbksg#faq","mainEntity":[{"@type":"Question","name":"How do I fix CS8618 non-nullable property uninitialized in C# without using null!?","acceptedAnswer":{"@type":"Answer","text":"Avoid `= null!`, which only silences the warning while the property stays null. Instead, mark the property `required` so callers must set it in an object initializer, initialize it in a constructor, or give it a real default value. `required` is usually the right choice for DTOs and models, since the compiler then forces callers to supply the value. Developers cleaning up nullable warnings across a .NET codebase keep up with C# practices on daily.dev."}},{"@type":"Question","name":"Does #nullable enable prevent NullReferenceException at runtime in C#?","acceptedAnswer":{"@type":"Answer","text":"No. Nullable reference types are compile-time static flow analysis only; at runtime string and string? are both System.String. Reflection, JSON deserializers and unannotated third-party libraries can still put null into a variable declared non-nullable. Default structs and `new string[10]` arrays also hold nulls without any compiler warning. Anyone migrating a legacy .NET project to nullable annotations can follow C# nullability tips on daily.dev."}},{"@type":"Question","name":"Why does System.Text.Json leave a non-nullable string property null when the JSON property is missing?","acceptedAnswer":{"@type":"Answer","text":"A non-nullable property with no `required` modifier and no initializer is simply never set when the JSON omits it, so it stays null. Enabling RespectNullableAnnotations only makes an explicit null for a non-nullable property throw; it does not catch absent properties. Marking the property `required` makes the missing value throw during deserialization. Teams hardening API input handling in .NET can stay current on deserialization pitfalls through daily.dev."}}]}
```

