❔ What could cause the compiler to not infer this nullability correctly
I get the warning here about possible null reference, but it is pretty obvious that this could be inferred by flow analysis.
I'm assuming something is wrong, old codebase, old compile etc. I just don's use .net as much anymore and I haven't kept up.
What should I look at?
6 Replies
see the question mark in the return type? that means it is allowed to return
null
look at nullable reference types, which are now enabled by default in new projects
ah yeah also you should do pageNumber.Value.ToString
I'm assuming that the pageNumber.Value could have been the issue, but I had to refactor my code anyways so I can't check
this solves your issue btw
query["PageNumber"] = pageNumber.ToString() ?? defaultValue;
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.