Closed PrzemyslawKlys closed 1 year ago
Would you like to start supporting NRT? Update a codebase with nullable reference types to improve null diagnostic warnings
I've read the document - and I have no clue what I am deciding on about 🤣🤣 and how it impacts this project or this particular issue. I am noob when it comes to programming so you need to treat me as such 😊
In general, this does not solve this issue :), but directs we to take care of NullReferenceException before an error occurs at runtime. NRT only helps to write safer code around NullReferenceException
I already have those warnings
I have both Visual Studio Enterprise and Resharper so one of those tells me to fix it anyways, but I do ignore it from time to time. I doubt in this case even NRT would help as it would have to know that _header may not exists at all if it's first not added to the document.
This particular issue will require improvement to create a header if it doesn't exist if Watermark requires, not just to fight null.
No, not exactly, if wordHeader
had been marked as a possible null, then the analyzers in the line would have noticed the problem even earlier -- by wordHeader
. Or vice versa, mark it as not possible zero, and then, by contract, passing the parameter, the user must already ensure that wordHeader
will not be null
Error thrown:
System.NullReferenceException HResult=0x80004003 Message=Object reference not set to an instance of an object. Source=OfficeIMO.Word StackTrace: at OfficeIMO.Word.WordWatermark..ctor(WordDocument wordDocument, WordSection wordSection, WordHeader wordHeader, WordWatermarkStyle style, String text) in C:\Support\GitHub\OfficeIMO\OfficeIMO.Word\WordWatermark.cs:line 98