Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

HTML and tag helpers will NRE if given a Linq expression w/ a static property #4856

@dougbu

Description

@dougbu

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. ExpressionMetadataProvider throws an NRE and does not give the user information about their mistake.

Repro
  1. Add a public static string StaticString { get; set; } property to a model type.
  2. Add a Linq expression using the static property in a view e.g. @Html.EditorFor(m => TopLevelClass.StaticString)
  3. Start the site
  4. Navigate to page using the view
Expected

A coherent error stating the StaticString property does not exist or the expression is not supported.

Actual

staticstring

Regression?

No; MVC 5 has the same issue.

Potential fix
  1. null-check memberExpression.Expression before dereferencing it.
  2. Either
    1. 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.
    2. Include use of a static property in the cases where ExpressionMetadataProvider throws an InvalidOperationException. Probably easiest to add the word "instance" once or twice in Resources.TemplateHelpers_TemplateLimitations and use the existing legalExpression variable.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions