warning CS8618: Non-nullable property 'X' must contain a non-null value when exiting constructor. Consider declaring the property as nullable
With nullable reference types enabled, a non-nullable reference property isn’t initialised by the constructor.
Seen on:
.NET
Meaning
It’s a warning (often treated as error). Choose: initialise it, make it nullable (string?), use required (C# 11), or = null! when another mechanism (EF, DI) sets it.
Common causes
- Property not assigned in constructor
- DTO/entity populated by deserializer/EF
- TreatWarningsAsErrors turning it into a build failure
⚡ Quick fix
- Use the required modifier
- Initialise with a default (= string.Empty)
- Make it nullable if null is valid
Detailed fix by platform
C#
- csharp
public class UserDto { public required string Email { get; init; } public string DisplayName { get; set; } = string.Empty; public string? Phone { get; set; } }
How to diagnose
- Semantics — Can it be null?
- Population — Who sets it?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- CS0103 error CS0103: The name 'x' does not exist in the current context
- CS0246 error CS0246: The type or namespace name 'X' could not be found (are you missing a using directive or an assembly reference?)
- CS1061 error CS1061: 'X' does not contain a definition for 'Y' and no accessible extension method 'Y' accepting a first argument of type 'X' could be found
Most viewed in .NET
Other ways to find it
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 7 Oct 2026