razor: Case-sensitive misspelled names and also missing namespaces cause a misleading error
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 dotnet/aspnetcore#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:
<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 dotnet/aspnetcore#9786 too.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 2
- Comments: 17 (9 by maintainers)
I agree this can be closed with the tooling fix.
@jjonescz In that case, is #9712 enough to mark this as fixed? The tooling experience for mistyped components is a lot better with it, but its unclear to me if there is still a compiler bug to fix here.
Tooling looks like this once the PR is merged:
Yes, the error message should be fixed by https://github.com/dotnet/razor/pull/9512 which should be in VS 17.9 Preview 2.
Opened https://github.com/dotnet/razor/pull/9712 to at least offer a code action that will help identify when component tags are cased incorrectly.
For the record, in the last VS previews, I do see a diagnostic from the compiler saying it can’t find the component, so it’s not complete guess work that the component is wrong.
44 upvotes/ 9k views https://stackoverflow.com/questions/57528902/the-attribute-names-could-not-be-inferred-from-bind-attribute-bind-value-err/57528903#57528903
Bringing into NET 7 planning.
Reopening and moving to the backlog to collect some more feedback.
@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!