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

**URL:** <https://forum.dotvvm.com/t/addmodelerror-giving-me-a-hard-time-in-nullable-enabled-code/172>\
**Category:** Discussion in English\
**Created:** [March 7, 2024, 4:28pm UTC](https://forum.dotvvm.com/t/addmodelerror-giving-me-a-hard-time-in-nullable-enabled-code/172 "2024-03-07T16:28:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarianV](https://forum.dotvvm.com/letter_avatar_proxy/v4/letter/m/c0e974/32.png) [@MarianV](https://forum.dotvvm.com/u/MarianV)\
**Post date:** [March 7, 2024, 4:28pm UTC](https://forum.dotvvm.com/t/addmodelerror-giving-me-a-hard-time-in-nullable-enabled-code/172/1 "2024-03-07T16:28:12Z")

</div>

![image](https://forum.dotvvm.com/uploads/default/original/1X/881121b6f6b72bc1f8b7b8ea957bf1d74965c43c.png)

…and nullable enabled code is practically everywhere

If I don’t try to use the null propagation operator (?.), this:  
 ![image](https://forum.dotvvm.com/uploads/default/original/1X/eb701c7e29084015b74e2d942116c96763ff0cec.png)

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

UPDATE

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

 ![image](https://forum.dotvvm.com/uploads/default/original/1X/f3795a513e2f0520001ca6b5510a5cbb6855e1f0.png)

---

<div class="post-metadata">

**Author:** ![MarianV](https://forum.dotvvm.com/letter_avatar_proxy/v4/letter/m/c0e974/32.png) [@MarianV](https://forum.dotvvm.com/u/MarianV)\
**Post date:** [March 7, 2024, 5:35pm UTC](https://forum.dotvvm.com/t/addmodelerror-giving-me-a-hard-time-in-nullable-enabled-code/172/2 "2024-03-07T17:35:50Z")

</div>

UPDATE

1. crashes, sigh:

 ![image](https://forum.dotvvm.com/uploads/default/original/1X/296f07c87e83c12ef6a2c4b94172c84da4cd5cf0.png)

---

<div class="post-metadata">

**Author:** ![exyi](https://forum.dotvvm.com/user_avatar/forum.dotvvm.com/exyi/32/9_2.png) [@exyi](https://forum.dotvvm.com/u/exyi)\
**Post date:** [March 7, 2024, 9:57pm UTC](https://forum.dotvvm.com/t/addmodelerror-giving-me-a-hard-time-in-nullable-enabled-code/172/3 "2024-03-07T21:57:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![MarianV](https://forum.dotvvm.com/letter_avatar_proxy/v4/letter/m/c0e974/32.png) [@MarianV](https://forum.dotvvm.com/u/MarianV)\
**Post date:** [March 7, 2024, 10:04pm UTC](https://forum.dotvvm.com/t/addmodelerror-giving-me-a-hard-time-in-nullable-enabled-code/172/4 "2024-03-07T22:04:40Z")

</div>

But something is missing here…

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

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

---

<div class="post-metadata">

**Author:** ![MarianV](https://forum.dotvvm.com/letter_avatar_proxy/v4/letter/m/c0e974/32.png) [@MarianV](https://forum.dotvvm.com/u/MarianV)\
**Post date:** [March 7, 2024, 10:25pm UTC](https://forum.dotvvm.com/t/addmodelerror-giving-me-a-hard-time-in-nullable-enabled-code/172/5 "2024-03-07T22:25:16Z")

</div>

it works

 ![image](https://forum.dotvvm.com/uploads/default/original/1X/3c708532c405edb6d385ab6179b94225011b729c.png)

---

<div class="post-metadata">

**Author:** ![exyi](https://forum.dotvvm.com/user_avatar/forum.dotvvm.com/exyi/32/9_2.png) [@exyi](https://forum.dotvvm.com/u/exyi)\
**Post date:** [March 8, 2024, 5:21pm UTC](https://forum.dotvvm.com/t/addmodelerror-giving-me-a-hard-time-in-nullable-enabled-code/172/6 "2024-03-08T17:21:15Z")

</div>

> [@MarianV](#):
>
> **nevermind** , found them in DotVVM’s `Context`

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