Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 26, 2025

The BC42328 Visual Basic compiler warning documentation was minimal and didn't help developers understand when and why this warning occurs. Users reported confusion about:

  • What "relaxed conversion" means in the context of delegates
  • Why some similar AddHandler/RemoveHandler statements trigger the warning while others don't
  • Why AddressOf is described as having "no effect" when it's syntactically required
  • How to properly address the warning

Changes Made

Enhanced the BC42328.md documentation with:

Comprehensive explanation: Added detailed description of Visual Basic's relaxed delegate conversion feature, explaining the four types of conversions (widening parameters/return types, omitting parameters, dropping return values).

Clear examples: Provided concrete code examples showing when BC42328 occurs versus when it doesn't:

' Event delegate expects (sender As Object, e As EventArgs)
Public Event SomeEvent As EventHandler

' Method with exact signature - no warning
Sub Handler1(sender As Object, e As EventArgs)
    ' Implementation
End Sub

' Method with omitted parameters - causes BC42328
Sub Handler2()
    ' Implementation  
End Sub

' Using AddHandler with exact match - no warning
AddHandler SomeEvent, AddressOf Handler1

' Using AddHandler with relaxed conversion - causes BC42328
AddHandler SomeEvent, AddressOf Handler2

Clarification of "no effect" message: Explained why the compiler says AddressOf "has no effect" (because it must create a wrapper delegate regardless) while still being syntactically required.

Multiple correction strategies: Provided four different approaches for addressing the warning:

  1. Variable assignment method (preserves exact semantics)
  2. Exact signature matching
  3. Lambda expression alternative
  4. Handles clause approach

Practical guidance: Added section on when the warning can safely be ignored for common scenarios.

Enhanced cross-references: Added links to related Visual Basic documentation including relaxed delegate conversion, AddHandler/RemoveHandler statements.

The enhanced documentation transforms a confusing, minimal error page into a comprehensive resource that helps Visual Basic developers understand and properly handle BC42328 warnings.

Fixes #10157.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.


Internal previews

📄 File 🔗 Preview link
docs/visual-basic/misc/bc42328.md The 'AddressOf' expression has no effect in this context because the method argument to 'AddressOf' requires a relaxed conversion to the delegate type of the event

@dotnet-policy-service dotnet-policy-service bot added the okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings. label Aug 26, 2025
…xed delegate conversions

Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] BC42328 could be a little better explained Improve BC42328 documentation with comprehensive explanation of relaxed delegate conversions Aug 26, 2025
@Copilot Copilot AI requested a review from BillWagner August 26, 2025 16:06
Copilot finished work on behalf of BillWagner August 26, 2025 16:06
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ready for final review once suggestions are applied.

@BillWagner BillWagner marked this pull request as ready for review August 27, 2025 15:21
@BillWagner BillWagner requested a review from a team as a code owner August 27, 2025 15:21
@BillWagner BillWagner requested a review from adegeo August 27, 2025 15:22
Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com>
@BillWagner BillWagner enabled auto-merge (squash) August 28, 2025 15:37
@BillWagner BillWagner merged commit 7597957 into main Aug 28, 2025
10 checks passed
@BillWagner BillWagner deleted the copilot/fix-10157 branch August 28, 2025 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dotnet-visualbasic/svc errors-warnings/subsvc okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BC42328 could be a little better explained
3 participants