Aspnetcore: Case-sensitive misspelled names and also missing namespaces cause a misleading error

Created on 16 Aug 2019  路  8Comments  路  Source: dotnet/aspnetcore

I just switched from Preview 6 to 8 and started getting lots of this error:

The attribute names could not be inferred from bind attribute 'bind-value'. Bind attributes should be of the form 'bind' or 'bind-value' along with their corresponding optional parameters like 'bind-value:event', 'bind:format' etc.

After some digging it turned out that I was getting this for two reasons:

  • Component names are now case-sensitive (I think that's related to #9860)
  • I was missing a namespace

So, the compiler was quite right, my code was bad, but the error message had me pulling my hair out for a while.

Say I've made a declaration like this:
c# <MyButton OnClick="Clicked" @bind-Value="@MyTextProperty"/>
Is there any way the error checking could identify that there's a binding statement and then throw a warning/exception if the component name (MyButton) doesn't match up to a component the error-checker can find? I think this ties back to #9786 too.

affected-medium area-blazor bug severity-minor

All 8 comments

@tomRedox If you mistype the component name (ex you forget to add an @using for the component namespace, or you misspelled the name) as long as you typed the name using Pascal casing the compiler will assume the element is meant to be a component and you should get a warning if the component name doesn't resolve. Are you saying that wasn't the case?

@danroth27 it looks like it could be the order the warnings are generated in. Where there's a binding I think the compiler is diagnosing a binding issue before it does the component name check, so is reporting the binding error instead of the component error:

When I mistype the name of this component (should be TelerikDropDownList)

image

The red squigglies are then on the binding rather than the whole component declaration, and I get the misleading error:

The attribute names could not be inferred from bind attribute 'bind-Value'. Bind attributes should be of the form 'bind' or 'bind-value' along with their corresponding optional parameters like 'bind-value:event', 'bind:format' etc.

If I then delete the binding, the squigglies now highlight the whole component:

image

and the error changes to

Found markup element with unexpected name 'TelerikdropDownList'. If this is intended to be a component, add a @using directive for its namespace.

Trying this experiment with a couple of other components seems to show the same pattern:

This gives the bind error:

image

This gives the unexpected name error:

image

Closing as we think this is not impacting the community. If there are more similar reports, we will reconsider.

@mkArtakMSFT sure thing. I put a question and answer on this on stack overflow about this which has only garnered 760 views and 3 upvotes, so it looks like people are working this out for themselves

Thanks for sharing some insights, @tomRedox.
Question views are not proven source of it being something users were hitting, Upvotes, in contrast, are - but, as you said, there are so far just 3 upvotes for the 6 months period. We'll wait more.

@mkArtakMSFT please fix this issue. I have spent the hours trying to figure out why by 2 way binding suddenly stopped working and what is supposedly wrong with it until I found the SO thread and learned that the error might be completely misleading.
yes it was my fault not remembering I moved the component files, but showing an error that leads people into the wrong direction causes to much frustration. please fix it.
thanks!

Reopening and moving to the backlog to collect some more feedback.

This has got a bit more traffic on Stack Overflow now, up to ~2.6k views and 21 upvotes across the Q&A. Looks like more people are getting tripped up by this as Blazor adoption increases.

Was this page helpful?
0 / 5 - 0 ratings