Skip to content

Conversation

@moscowchill
Copy link

Summary

This PR fixes two critical issues:

  1. Build failures on Linux with .NET SDK 8.0 due to C# language version detection issues
  2. WMI tool crash after successful command execution due to NetworkStream disposal race condition

Build System Fixes

Projects targeting netstandard2.0 and netstandard2.1 were defaulting to C# 7.3 and 8.0 respectively, despite the global LangVersion 12.0 setting. This caused build failures when using C# 9.0+ features.

Changes:

  • Add LangVersion 12.0 to src/Directory.Build.props for all src/ projects
  • Add explicit LangVersion 12.0 to three projects that need it:
    • Titanis.SourceGen.csproj (netstandard2.0)
    • Titanis.Winterop.Security.csproj (netstandard2.1)
    • Titanis.Winterop.FileInfo.csproj (netstandard2.1)

Result: Titanis now builds successfully on Linux with .NET SDK 8.0

Bug Fix: NetworkStream Disposal Race Condition

File: src/net/Titanis.DceRpc/Client/RpcClientChannel.cs
Method: CancelRequest(PendingRequest, CancellationToken)

Issue

WMI commands complete successfully but crash immediately after with:
```
Unhandled exception. System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.Sockets.NetworkStream'.
```

Root Cause

Race condition in CancelRequest() method. When a timeout fires or connection closes during cleanup, the cancellation callback attempts to send a CoCancel PDU, but the NetworkStream has already been disposed.

Fix

Add try-catch blocks to gracefully handle ObjectDisposedException and other exceptions during cancellation. Since the request is already being cancelled, failures in sending the cancel PDU are not critical.

Testing

Tested on Linux x86-64 with .NET SDK 8.0.415:

  • ✅ Build succeeds without errors
  • ✅ WMI exec commands complete successfully without crashes

Impact

  • Risk: Low - only affects error handling during cancellation
  • Value: High - prevents crashes after successful operations
  • Compatibility: No API or behavior changes, fully backward compatible

## Build System Fixes

- Add LangVersion 12.0 to src/Directory.Build.props to fix C# language version detection for netstandard2.x projects
- Add explicit LangVersion 12.0 to Titanis.SourceGen.csproj (netstandard2.0)
- Add explicit LangVersion 12.0 to Titanis.Winterop.Security.csproj (netstandard2.1)
- Add explicit LangVersion 12.0 to Titanis.Winterop.FileInfo.csproj (netstandard2.1)

Previously, netstandard2.0 and netstandard2.1 projects defaulted to C# 7.3 and 8.0,
causing build failures with C# 9.0+ and 12.0 features. This enables building on Linux
with .NET SDK 8.0.

## Bug Fix

- Fix NetworkStream disposal race condition in RpcClientChannel.CancelRequest()

Add exception handling to gracefully handle ObjectDisposedException when the
NetworkStream is disposed during cleanup before the cancellation callback fires.
This prevents crashes after successful WMI command execution.

Fixes: Unhandled ObjectDisposedException crash in WMI tool after successful operations

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
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.

1 participant