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

Closed

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.

Activity

  1. dougbu commented on Jun 11, 2016

    @dougbu
    ContributorAuthor

    My thanks to @mnltejaswini who first discovered this issue when reviewing the code.

  2. added this to the Backlog milestone on Jun 13, 2016
  3. rynowak commented on Jul 17, 2017

    @rynowak
    Contributor

    This was fixed by a23307e

  4. modified the milestones: 2.0.0, Backlog on Jul 17, 2017
  5. self-assigned this
    on Jul 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions