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.
The text was updated successfully, but these errors were encountered:
MVC generally does not support
static
properties e.g.ModelMetadata.Properties
excludesstatic
properties. However the failure mode is poor when astatic
property is used in a Linq expression.ExpressionMetadataProvider
throw
s an NRE and does not give the user information about their mistake.Repro
public static string StaticString { get; set; }
property to a model type.static
property in a view e.g.@Html.EditorFor(m => TopLevelClass.StaticString)
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
-checkmemberExpression.Expression
before dereferencing it.static
properties to the casesExpressionMetadataProvider
supports. This would be similar to how this class supports Linq expressions containing fields though MVC's field support is generally very limited.static
property in the cases whereExpressionMetadataProvider
throw
s anInvalidOperationException
. Probably easiest to add the word "instance" once or twice inResources.TemplateHelpers_TemplateLimitations
and use the existinglegalExpression
variable.The text was updated successfully, but these errors were encountered: