Skip to content

fix: prevent duplicate middleware registration in ChannelCloudAdapterWithErrorHandlerBase - #191

Merged
lmarcos000 merged 1 commit into
Encamina:mainfrom
LuisM000:@lmarcos/fix_cloud_adapter_duplicate_middlewares
Jun 1, 2026
Merged

lmarcos000 merged 1 commit into
Encamina:mainfrom
LuisM000:@lmarcos/fix_cloud_adapter_duplicate_middlewares

Conversation

@LuisM000

Copy link
Copy Markdown
Contributor

The Microsoft Agents SDK now registers middlewares internally during the CloudAdapter base constructor call. Since ChannelCloudAdapterWithErrorHandlerBase was passing adapterOptions.Middlewares.ToArray() to the base constructor and subclasses were also calling InitializeMiddlewares, middlewares were being registered twice.

Motivation and Context

Upgrading the Microsoft Agents SDK introduced a breaking change in how CloudAdapter handles middlewares internally. Passing the middleware collection to the base constructor caused duplicates when InitializeMiddlewares or InitializeDefaultMiddlewares was subsequently called by subclasses.

The fix passes an empty array to the base constructor instead, preventing the SDK from auto-registering middlewares. Subclasses are now responsible for explicitly calling InitializeDefaultMiddlewares or InitializeMiddlewares in their own constructor to register middlewares in a controlled order.

Type of change

  • ✅ The code builds clean without any errors or warnings
  • ✅ Bug fix (non-breaking change which fixes an issue)

Checklist

  • ✅ My code follows the style guidelines of this project
  • ✅ I have performed a self-review of my own code
  • ✅ I have commented my code, particularly in hard-to-understand areas
  • ✅ My changes generate no new warnings
  • ✅ I didn't break anyone 😄

Updated `ChannelCloudAdapterWithErrorHandlerBase` to remove automatic middleware registration by the base constructor. Subclasses must now explicitly call `InitializeDefaultMiddlewares` or `InitializeMiddlewares` to register middlewares in a controlled order. Updated the constructor to pass an empty middleware array.

Incremented version to `10.0.5` in `Directory.Build.props` and updated the changelog to reflect these changes.
@lmarcos000 lmarcos000 added the bug Something isn't working label May 26, 2026
@lmarcos000
lmarcos000 merged commit 3a12621 into Encamina:main Jun 1, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants