public class Document { private string file_path; public Document() { InitializeDocument(); } private void InitializeDocument() { file_path = @"C:\mydocument.doc"; } }

I get an error:

CS8618: Non-nullable field 'file_path' must contain a non-null value when exiting constructor. Consider adding 'required' modifier or declaring the field as nullable.

This is really strange because upon exiting the variable file_path is not null!

JohnyL's user avatar

The compiler only checks direct variable assignments within constructor, and it does not check all the possible call trees, hence it ignores the otherwise obvious assignment.

AgentFire's user avatar

Sign up to request clarification or add additional context in comments.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.