Automatic code fixes unavailable for BL0015 in components and BL0016 in all project types (.NET 11)
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 290
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Describe the bug
The JavaScript interop analyzer provides automatic code fixes for certain warnings, but the availability is inconsistent and limited:
**BL0015 ("Make [JSInvokable] method public"):**
- Code fix IS available in Razor Class Library (.cs class files)
- Code fix IS NOT available in Razor component (.razor) files in Server and Client projects
- Developers using .razor components must manually edit code, while RCL developers get automatic fixes for the same warning
**BL0016 ("Guard JavaScript interop calls"):**
- Code fix is NOT available in any project type (Server, Client, or RCL)
- Developers must manually add try/catch blocks or restructure code to move calls to OnAfterRender
This creates a poor developer experience: the analyzer identifies the problem but provides no automated solution in most scenarios.
### Expected Behavior
- **BL0015 code fix should work in .razor component files** (Razor components in Server and Client projects), just as it does in RCL files
- **BL0016 code fix should be available** (the IDE should provide a suggestion for wrapping in try/catch)
At the very least, both warnings should offer consistent code fix availability across all project types.
### Steps To Reproduce
### Steps To Reproduce
1. Create a Blazor Web App targeting .NET 11 with Interactive Server render mode
2. In a .razor component file, create a private method with `[JSInvokable]` attribute:
```
[JSInvokable]
private async Task MyPrivateMethod()
{
// Code here
}
```
3. Build the project - BL0015 warning appears
4. In Visual Studio, click on the warning and look for Quick Actions (Alt+.)
5. Observe: No automatic code fix is offered
**Contrast with RCL:**
1. Create the same private `[JSInvokable]` method in an RCL .cs class file
2. Build - BL0015 warning appears
3. In Visual Studio, click on the warning and look for Quick Actions (Alt+.)
4. Observe: "Make [JSInvokable] method public" code fix IS available
### Exceptions (if any)
No exceptions are thrown. The issue is purely about missing IDE code fix support.
### .NET Version
11.0.100-preview.7.26381.103
### Anything else?
**Test Environments:**
- Visual Studio 2022 (latest)
- Windows 11
- .NET 11 Preview 7
**Affected Code Patterns:**
| Warning | Project Type | Code Fix | Impact |
|---------|--------------|----------|--------|
| BL0015 | RCL (.cs class) | ✓ Available | Automatic fix works |
| BL0015 | Server (.razor) | ✗ Not Available | Manual fix required |
| BL0015 | Client (.razor) | ✗ Not Available | Manual fix required |
| BL0016 | All projects | ✗ Not Available | Manual fix required |
**Reproduction Repository:**
- **Sample App:** [validation-68483-javascript-interop](https://github.com/VigneshwaranGovindharajan/validation-68483-javascript-interop/tree/main/src/BlazorJsInteropDiagnosticsApp)
- **Test Results:** [Full Validation Report](https://github.com/VigneshwaranGovindharajan/validation-68483-javascript-interop/blob/main/test-report/ValidationReport.docx)
### Additional Context
The inconsistency between RCL and component code fixes creates developer confusion. Developers expect that if a warning exists in the IDE, there should be a way to fix it automatically. When fixes work in one project type but not another for the same warning, it feels like a gap in the analyzer implementation.
For BL0016, having no code fix at all means developers must learn the correct pattern from documentation rather than getting guidance from the IDE when they violate it. An automatic suggestion to wrap calls in try/catch would improve the developer experience significantly.
Contributor guide
Research direction
Start with the analyzer and code-fix entry points for BL0015 and BL0016, comparing behavior in .razor components with RCL .cs files. Reproduce the issue in the linked Blazor sample and check Visual Studio Quick Actions. Done means BL0015 is offered in Server and Client .razor files and BL0016 has a suitable fix across the listed project types.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, javascript
- Domain
- developer-experience, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100