Skip to content

False positive NSB0033 for Handle methods implementing a derived IHandleMessages#7770

Merged
danielmarbach merged 5 commits into
Particular:masterfrom
SimonCropp:Fix-NSB0033-false-positive-for-Handle-methods-implementing-a-derived-IHandleMessages
May 26, 2026
Merged

False positive NSB0033 for Handle methods implementing a derived IHandleMessages#7770
danielmarbach merged 5 commits into
Particular:masterfrom
SimonCropp:Fix-NSB0033-false-positive-for-Handle-methods-implementing-a-derived-IHandleMessages

Conversation

@SimonCropp
Copy link
Copy Markdown
Contributor

@SimonCropp SimonCropp commented May 25, 2026

Symptoms

The compiler reports a false positive NSB0033 diagnostic for Handle methods implementing implementing an interface derived from IHandleMessages<T>.

Who's affected

Users of NServiceBus 10.2.0 using an intermediate interface to identify handlers rather than using IHandleMessages<T> directly.`

Root cause

The use case of an intermediate marker interface was not considered in the analyzer design.

Original bug report

Fix NSB0033 false positive for Handle methods implementing a derived IHandleMessages interface The mixed-style check treated any Handle(message, context, ...) method with more than two parameters as convention-based, even when that method is the implementation of an interface member. This produced a false positive for handlers that implement a custom interface deriving from IHandleMessages which exposes an extended Handle signature (e.g. an extra CancellationToken) backed by a default interface method that forwards to the two-parameter IHandleMessages.Handle.
IsValidConventionBasedHandleMethod now classifies a Handle method that implements any interface member as interface-based rather than convention-based, regardless of parameter count.

…IHandleMessages

Fix NSB0033 false positive for Handle methods implementing a derived IHandleMessages<T> interface
The mixed-style check treated any Handle(message, context, ...) method with more than
two parameters as convention-based, even when that method is the implementation of an
interface member. This produced a false positive for handlers that implement a custom
interface deriving from IHandleMessages<T> which exposes an extended Handle signature
(e.g. an extra CancellationToken) backed by a default interface method that forwards to
the two-parameter IHandleMessages<T>.Handle.
IsValidConventionBasedHandleMethod now classifies a Handle method that implements any
interface member as interface-based rather than convention-based, regardless of
parameter count.
@danielmarbach danielmarbach force-pushed the Fix-NSB0033-false-positive-for-Handle-methods-implementing-a-derived-IHandleMessages branch from 5be985d to 455c0ef Compare May 26, 2026 07:48
@danielmarbach
Copy link
Copy Markdown
Contributor

@SimonCropp thanks for the PR with the fix and the reproduction. This is tremendously helpful! I have pushed a few changes and will wait for the others to also review it.

@andreasohlund andreasohlund added this to the 10.2.1 milestone May 26, 2026
@danielmarbach danielmarbach merged commit 69821f7 into Particular:master May 26, 2026
4 checks passed
@SimonCropp
Copy link
Copy Markdown
Contributor Author

thanks peoples

@danielmarbach danielmarbach changed the title Fix NSB0033 false positive for Handle methods implementing a derived IHandleMessages False positive NSB0033 for Handle methods implementing a derived IHandleMessages May 27, 2026
DavidBoike pushed a commit that referenced this pull request May 27, 2026
* Delete saga storage directory in persistence tests Cleanup (#7771)

Delete saga storage directory in persistence tests Cleanup
PersistenceTestsConfiguration.Configure created saga storage under
%TEMP%\.sagas\<TestID> but Cleanup was a no-op, so every persistence
test run leaked its directory and they accumulated indefinitely.
Track the storage location and recursively delete it in Cleanup

* Update dependency PolySharp to 1.16.0 (#7772)

Co-authored-by: dependencyupdates[bot] <218638057+dependencyupdates[bot]@users.noreply.github.com>

* Fix NSB0033 false positive for Handle methods implementing a derived IHandleMessages (#7770)

* Fix NSB0033 false positive for Handle methods implementing a derived IHandleMessages

Fix NSB0033 false positive for Handle methods implementing a derived IHandleMessages<T> interface
The mixed-style check treated any Handle(message, context, ...) method with more than
two parameters as convention-based, even when that method is the implementation of an
interface member. This produced a false positive for handlers that implement a custom
interface deriving from IHandleMessages<T> which exposes an extended Handle signature
(e.g. an extra CancellationToken) backed by a default interface method that forwards to
the two-parameter IHandleMessages<T>.Handle.
IsValidConventionBasedHandleMethod now classifies a Handle method that implements any
interface member as interface-based rather than convention-based, regardless of
parameter count.

* Add test to verify NSB0033 does not report false positive for derived handler interfaces

* Update handler validation to support custom interface implementation types and introduce sensible fast path checks

* Regression test

* Fix discover of handler interface methods

---------

Co-authored-by: Daniel Marbach <danielmarbach@users.noreply.github.com>

* Fix string append method in PipelineStepDiagnostics

This causes a warning when compiled using .NET 11 Preview 4.

* Mark source-generated handler adapters with CompilerGeneratedAttribute (#7778)

* Add CompilerGenerated attribute to generated handlers

* Align attribute qualifying

* Hide the other source gen only methods

* Emit GeneratedCodeAttribute to generated infrastructure classes and methods

---------

Co-authored-by: Daniel Marbach <danielmarbach@users.noreply.github.com>

---------

Co-authored-by: Simon Cropp <simon.cropp@gmail.com>
Co-authored-by: dependencyupdates[bot] <218638057+dependencyupdates[bot]@users.noreply.github.com>
Co-authored-by: Daniel Marbach <danielmarbach@users.noreply.github.com>
Co-authored-by: John Simons <john.simons@particular.net>
@DavidBoike
Copy link
Copy Markdown
Member

@SimonCropp 10.2.1 now released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants