Refactor: Use TryParse in view models for safer numeric input parsing#14323
Merged
benhillis merged 2 commits intomicrosoft:masterfrom Mar 2, 2026
Merged
Refactor: Use TryParse in view models for safer numeric input parsing#14323benhillis merged 2 commits intomicrosoft:masterfrom
benhillis merged 2 commits intomicrosoft:masterfrom
Conversation
Replaces parsing logic with TryParse across view models to prevent overflow/format crashes from invalid user input. Specifically fixes the VM Idle Timeout crash reported in microsoft#14312, while improving stability for other numeric settings.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens numeric settings input handling in the WSL Settings app by replacing exception-throwing numeric conversions with TryParse in several settings view models, preventing crashes from overflow/invalid user input (notably the VM Idle Timeout crash in #14312).
Changes:
- Replace
Convert.ToInt32/ToUInt64withInt32.TryParse/UInt64.TryParsein multiple numeric-setting setters. - On parse failure (e.g., overflow), revert the UI by raising
OnPropertyChanged()instead of crashing. - Apply the same safer parsing pattern to optional features, networking, memory/processor, and filesystem settings.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/windows/wslsettings/ViewModels/Settings/OptionalFeaturesViewModel.cs | Uses Int32.TryParse for VM Idle Timeout to avoid overflow crashes and revert invalid input. |
| src/windows/wslsettings/ViewModels/Settings/NetworkingViewModel.cs | Uses Int32.TryParse for Initial Auto Proxy Timeout to prevent invalid input crashes. |
| src/windows/wslsettings/ViewModels/Settings/MemAndProcViewModel.cs | Uses TryParse for processor count, memory size, and swap size numeric inputs to prevent exceptions. |
| src/windows/wslsettings/ViewModels/Settings/FileSystemViewModel.cs | Uses UInt64.TryParse for Default VHD Size to avoid invalid/overflow conversion crashes. |
Member
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
benhillis
reviewed
Mar 1, 2026
benhillis
approved these changes
Mar 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of the Pull Request
Replaces parsing logic with TryParse across view models to prevent overflow/format crashes from invalid user input. Specifically fixes the VM Idle Timeout crash reported in #14312, while improving stability for other numeric settings. Also removes an orphaned reference to SystemdSettingsExpander in OptionalFeaturesPage.xaml.cs which caused a Debug.Assert failure and crashed the application when the Optional Features page was opened. This expander is no longer present in the XAML markup.
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed