You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
MVC generally does not support static properties e.g. ModelMetadata.Properties excludes static properties. However the failure mode is poor when a static property is used in a Linq expression. ExpressionMetadataProviderthrows an NRE and does not give the user information about their mistake.
Repro
Add a public static string StaticString { get; set; } property to a model type.
Add a Linq expression using the static property in a view e.g. @Html.EditorFor(m => TopLevelClass.StaticString)
Start the site
Navigate to page using the view
Expected
A coherent error stating the StaticString property does not exist or the expression is not supported.
Actual
Regression?
No; MVC 5 has the same issue.
Potential fix
null-check memberExpression.Expression before dereferencing it.
Either
Add static properties to the cases ExpressionMetadataProvider supports. This would be similar to how this class supports Linq expressions containing fields though MVC's field support is generally very limited.
Include use of a static property in the cases where ExpressionMetadataProviderthrows an InvalidOperationException. Probably easiest to add the word "instance" once or twice in Resources.TemplateHelpers_TemplateLimitations and use the existing legalExpression variable.