@@ -275,10 +275,22 @@ private static void Execute(
275275 var crossAssemblyCallSites = new List < CallSiteInfo > ( ) ;
276276 var crossAssemblyHandlerMessageTypes = new HashSet < string > ( crossAssemblyHandlerList . Select ( h => h . MessageType . FullName ) ) ;
277277
278+ // Find message types with multiple local handlers — these are ambiguous and
279+ // must NOT have interceptors generated (would cause CS9153: intercepted multiple times).
280+ var ambiguousMessageTypes = new HashSet < string > ( filteredHandlers
281+ . GroupBy ( h => h . MessageType . FullName )
282+ . Where ( g => g . Count ( ) > 1 )
283+ . Select ( g => g . Key ) ) ;
284+
278285 var handlersWithInfo = new List < HandlerInfo > ( ) ;
279286 foreach ( var handler in filteredHandlers )
280287 {
281- callSitesByMessage . TryGetValue ( handler . MessageType , out var handlerCallSites ) ;
288+ // Don't assign call sites when multiple handlers exist for the same message type,
289+ // since each would generate an interceptor for the same call site.
290+ CallSiteInfo [ ] ? handlerCallSites = null ;
291+ if ( ! ambiguousMessageTypes . Contains ( handler . MessageType . FullName ) )
292+ callSitesByMessage . TryGetValue ( handler . MessageType , out handlerCallSites ) ;
293+
282294 var applicableMiddleware = GetApplicableMiddlewares ( allMiddleware . ToImmutableArray ( ) , handler , configuration , out var orderingDiagnostics ) ;
283295
284296 // Resolve effective handler lifetime: use explicit lifetime if set, otherwise use project default
@@ -287,7 +299,7 @@ private static void Execute(
287299 // Merge assembly-level authorization defaults into handler authorization info
288300 var mergedAuth = MergeAuthorizationDefaults ( handler . Authorization , endpointDefaults ) ;
289301
290- handlersWithInfo . Add ( handler with { CallSites = new ( handlerCallSites ) , Middleware = applicableMiddleware , Lifetime = resolvedHandlerLifetime , OrderingDiagnostics = new ( orderingDiagnostics . ToArray ( ) ) , Authorization = mergedAuth } ) ;
302+ handlersWithInfo . Add ( handler with { CallSites = new ( handlerCallSites ?? [ ] ) , Middleware = applicableMiddleware , Lifetime = resolvedHandlerLifetime , OrderingDiagnostics = new ( orderingDiagnostics . ToArray ( ) ) , Authorization = mergedAuth } ) ;
291303 }
292304
293305 // Collect call sites that need cross-assembly interceptors
0 commit comments