Skip to content

Fix C# build errors: TimeSpan conversion, missing using statements, and nullable reference types#7

Merged
cmcxn merged 2 commits into
masterfrom
copilot/fix-3db97df7-6552-42af-8e34-67aded82bd44
Sep 16, 2025
Merged

Fix C# build errors: TimeSpan conversion, missing using statements, and nullable reference types#7
cmcxn merged 2 commits into
masterfrom
copilot/fix-3db97df7-6552-42af-8e34-67aded82bd44

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Sep 16, 2025

This PR resolves several C# compilation errors that were preventing the project from building successfully.

Issues Fixed

1. TimeSpan to int conversion errors (CS0029)

The WSManConnectionInfo timeout properties expect int values in milliseconds, but were being assigned TimeSpan objects directly:

// Before - caused CS0029 compilation error
connectionInfo.OperationTimeout = TimeSpan.FromMinutes(2);
connectionInfo.OpenTimeout = TimeSpan.FromSeconds(30);

// After - converts TimeSpan to milliseconds
connectionInfo.OperationTimeout = (int)TimeSpan.FromMinutes(2).TotalMilliseconds;
connectionInfo.OpenTimeout = (int)TimeSpan.FromSeconds(30).TotalMilliseconds;

2. Missing namespace for PSRemotingTransportException (CS0246)

Added the required using statement to resolve PowerShell remoting exceptions:

using System.Management.Automation.Remoting;

This fixes the compilation error when catching PSRemotingTransportException in the remote PowerShell execution code.

3. Nullable reference type warnings (CS8603, CS8604, CS8612)

Updated event declarations, method signatures, and property types to properly handle nullable reference types:

  • PropertyChangedEventHandlerPropertyChangedEventHandler?
  • Method parameters like string propertyNamestring? propertyName
  • String properties that can be null now use string? type annotations
  • Updated helper methods SecureStringToString and StringToSecureString to handle nullable inputs/outputs

Impact

  • Resolves all compilation errors that were blocking builds
  • Improves type safety with proper nullable annotations
  • Maintains backward compatibility - no breaking changes to public API
  • Follows C# 8.0+ nullable reference type best practices

The changes are minimal and surgical, addressing only the specific compilation issues without modifying application logic or functionality.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

…and nullable annotations

Co-authored-by: cmcxn <84500762+cmcxn@users.noreply.github.com>
Copilot AI changed the title [WIP] The failing job encountered these key errors: 1. **Type Conversion Error** In MainWindow.xaml.cs at lines 1490 and 1491, the code attempts to assign a System.TimeSpan value to an int variable: ``` error CS0029: Cannot implicitly conve... Fix C# build errors: TimeSpan conversion, missing using statements, and nullable reference types Sep 16, 2025
Copilot AI requested a review from cmcxn September 16, 2025 01:10
@cmcxn cmcxn marked this pull request as ready for review September 16, 2025 01:17
@cmcxn cmcxn merged commit 9b71374 into master Sep 16, 2025
2 checks passed
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.

2 participants