Clarify [EventHandler] tag helper discovery logic and avoid exception #10828
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes an issue that @tmat pointed out to me over email. In a recent change (#10720), I added a call to
Assumed.Unreachable()
when[EventHandler]
tag helper discovery encounters an attribute with invalid constructor attributes. However, throwing an exception during tag helper discovery is usually the wrong approach. Normally, if Roslyn symbols aren't in the proper shape during tag helper discovery, Razor will simply not produce a tag helper. (We do support diagnostics for tag helpers, but those are usually reserved for warnings and errors that are related to a tag helper's data that would make it unusable, such as a name containing whitespace.)It turns out that the "unreachable" condition wasn't actually all that unreachable and @tmat was hitting it while working on hot reload tests. So, I've changed the code to make the success conditions clearer, i.e., the attribute data must match one of the two constructor calls. And, I changed the logic to simply skip
[EventHandler]
attributes that don't meet the success conditions.