AddModelError() giving me a hard time in nullable enabled code

…and nullable enabled code is practically everywhere

If I don’t try to use the null propagation operator (?.), this:

This happens despite the null guard above. Null forgiving operator (suffixed !) is out of the question. I’ll try with non-lambda effective param.


  1. non-lambda param seems complicated and abandoned it;


  1. crashes, sigh:

You have to use the ! suffix operator… The lambda expression isn’t executed, it will never fail on null reference. For some reason, MS decided to keep Linq.Expressions on C# version 5 or so, we can’t do anything about the ?. operator. Thanks god the ! operator is allowed there.

We use the expression to make the validation path from it, which is why the condition fails. I guess we could pattern-match the null-check conditions, but ehh, it isn’t exactly simple and then the API doesn’t serve even the purpose of simplifying the validation paths. You can also use the AddModelError("OperationFinalizationSectino/SelectedFinalizationDate", ...) overload and avoid this automatic translation entirely.

1 Like

But something is missing here…

That overload is not found and also this.AddRawModelError() not found. No suggestions for using namespaces.

nevermind, found them in DotVVM’s Context
I have used AddRawModelError because AddModelError with first param as string is warned of as being obsolete.

it works

yea, sorry, use the AddRawModelError on the IDotvvmRequestContext. The other is only on ViewModel as it needs to know the VM type.