Skip to content

fix: handle multiple IContextCheck interfaces in AddChecks#2425

Closed
Sim-hu wants to merge 1 commit intoDSharpPlus:masterfrom
Sim-hu:fix/add-checks-multiple-interfaces
Closed

fix: handle multiple IContextCheck interfaces in AddChecks#2425
Sim-hu wants to merge 1 commit intoDSharpPlus:masterfrom
Sim-hu:fix/add-checks-multiple-interfaces

Conversation

@Sim-hu
Copy link

@Sim-hu Sim-hu commented Mar 23, 2026

When a class implements more than one IContextCheck<T> interface, AddChecks(Assembly) throws an AmbiguousMatchException because it uses Type.GetInterface() which only expects a single match.

This switches to GetInterfaces() with a predicate to find the right interface by namespace and name, which is the same approach already used in the single-type AddCheck(Type) overload. Keeps things consistent and fixes the crash.

Fixes #2262

Use GetInterfaces() instead of GetInterface() to avoid
AmbiguousMatchException when a class implements multiple
IContextCheck<T> interfaces.

Fixes DSharpPlus#2262
@akiraveliara
Copy link
Member

what specifically do you mean by "keeps things consistent"?

@Sim-hu
Copy link
Author

Sim-hu commented Mar 24, 2026

The single-type AddCheck(Type) overload already uses GetInterfaces() with a namespace/name check (around line 343). This PR just brings AddChecks(Assembly) in line with that same approach instead of using GetInterface().

@akiraveliara
Copy link
Member

given the author's account, closing as AI

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CommandsExtension.AddChecks(Assembly assembly) throws when one class implements multiple IContextCheck<T>

2 participants