Skip to content

Remove dead code: options ??= new() in McpServerImpl constructor#1322

Merged
stephentoub merged 2 commits intomainfrom
copilot/remove-dead-code-on-line-61
Feb 20, 2026
Merged

Remove dead code: options ??= new() in McpServerImpl constructor#1322
stephentoub merged 2 commits intomainfrom
copilot/remove-dead-code-on-line-61

Conversation

Copy link
Contributor

Copilot AI commented Feb 20, 2026

Throw.IfNull(options) already guarantees options is non-null before reaching the ??= assignment, making it unreachable dead code.

Change

  • McpServerImpl.cs: Remove options ??= new(); and its trailing blank line from the constructor — the preceding null guard renders it impossible to execute.

Before:

Throw.IfNull(transport);
Throw.IfNull(options);

options ??= new();

_sessionTransport = transport;

After:

Throw.IfNull(transport);
Throw.IfNull(options);

_sessionTransport = transport;
Original prompt

In src/ModelContextProtocol.Core/Server/McpServerImpl.cs, line 61 contains:

options ??= new();

This is dead code. On line 59, Throw.IfNull(options) already validates that options is non-null and will throw an ArgumentNullException if it is null. Therefore, the null-coalescing assignment on line 61 can never execute its right-hand side — options is guaranteed to be non-null at that point.

Fix: Remove line 61 (options ??= new();) and the blank line following it (line 62) to keep formatting clean. The surrounding code (lines 58–63) currently looks like:

        Throw.IfNull(transport);
        Throw.IfNull(options);

        options ??= new();

        _sessionTransport = transport;

It should become:

        Throw.IfNull(transport);
        Throw.IfNull(options);

        _sessionTransport = transport;

This pull request was created from Copilot chat.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…pServerImpl

Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Copilot AI changed the title [WIP] Remove dead code from McpServerImpl.cs Remove dead code: options ??= new() in McpServerImpl constructor Feb 20, 2026
Copilot AI requested a review from stephentoub February 20, 2026 02:12
@stephentoub stephentoub marked this pull request as ready for review February 20, 2026 02:13
@stephentoub stephentoub enabled auto-merge (squash) February 20, 2026 02:13
@stephentoub stephentoub merged commit bd758ff into main Feb 20, 2026
9 of 10 checks passed
@stephentoub stephentoub deleted the copilot/remove-dead-code-on-line-61 branch February 20, 2026 03:41
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.

3 participants

Comments