The FieldConfiguration returned from a ValidationMessageFor would throw on it's ToHtmlString call made by Razor.
The reason is that the _field member evaluates down to a call to HtmlHelper.ValidationMessageFor from System.Web.Mvc and, at least in MVC5, that returns null when there is no message to be had - which is most of the time.
I didn't research in what exactly the difference to the test project is that it makes the bug surface for me, but the MVC version difference is the one obvious suspect.
The suggested little addition of robustness fixes things for me.
The
FieldConfiguration
returned from aValidationMessageFor
would throw on it'sToHtmlString
call made by Razor.The reason is that the
_field
member evaluates down to a call toHtmlHelper.ValidationMessageFor
fromSystem.Web.Mvc
and, at least in MVC5, that returnsnull
when there is no message to be had - which is most of the time.I didn't research in what exactly the difference to the test project is that it makes the bug surface for me, but the MVC version difference is the one obvious suspect.
The suggested little addition of robustness fixes things for me.