You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you compile this code, Visual Basic shows the BC42328 warning for the second `AddHandler` statement because `OnSimpleComplete` doesn't match the `EventHandler` signature exactly.
66
+
50
67
## Why AddressOf appears to have "no effect"
51
68
52
69
The warning message states that `AddressOf` "has no effect" because Visual Basic must create a wrapper delegate for the relaxed conversion regardless. The `AddressOf` operator doesn't change how the compiler handles the conversion: the same result occurs whether you use `AddressOf` or not in relaxed conversion scenarios.
@@ -57,36 +74,163 @@ However, `AddressOf` is still syntactically required in `AddHandler` and `Remove
57
74
58
75
## To correct this error
59
76
60
-
You have several options depending on your needs:
77
+
You have several options depending on your needs. Using the `FileProcessor` example from above, here are the different ways to resolve the BC42328 warning:
61
78
62
-
-**Assign to a variable first (preserves exact semantics):**
79
+
### Option 1: Assign to a variable first (preserves exact semantics)
63
80
64
-
```vb
65
-
DimhandlerAsEventHandler=AddressOfHandler2
66
-
AddHandlerSomeEvent,handler
67
-
```
81
+
```vb
82
+
PublicSubStartProcessing()
83
+
' Create delegate variable first - this eliminates the warning
This example shows how the warning occurs in realistic scenarios and demonstrates multiple ways to resolve it.
90
234
91
235
## When you can ignore this warning
92
236
@@ -95,8 +239,27 @@ This warning is often safe to ignore when:
95
239
- Your handler method intentionally omits parameters it doesn't need.
96
240
- You're using a simpler method signature for cleaner code.
97
241
- The performance impact is negligible for your application.
242
+
- You're prototyping or writing quick utility code where clarity matters more than efficiency.
98
243
99
-
The relaxed conversion works correctly; this warning just indicates a minor efficiency consideration.
244
+
The relaxed conversion works correctly; this warning just indicates a minor efficiency consideration. The compiler creates a wrapper delegate automatically, which adds a small performance overhead but doesn't affect functionality.
245
+
246
+
### Example of when ignoring is appropriate
247
+
248
+
```vb
249
+
PublicClassQuickLogger
250
+
PublicEventLogMessageAsAction(OfString,DateTime)
251
+
252
+
' Simple handler that ignores the timestamp parameter
253
+
PrivateSubWriteToConsole()
254
+
Console.WriteLine("Something was logged")
255
+
EndSub
256
+
257
+
PublicSubSetupLogging()
258
+
' This generates BC42328, but it's fine for simple scenarios
0 commit comments