CS8618 🟪 .NET

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

  1. Use the required modifier
  2. Initialise with a default (= string.Empty)
  3. Make it nullable if null is valid

Detailed fix by platform

C#

  1. 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

  1. Semantics — Can it be null?
  2. 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:

🧠 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.