Skip to content

Fix KeyNotFoundException when simulator lacks runtimeIdentifier or version#1501

Merged
simonrozsival merged 9 commits intomainfrom
copilot/fix-simulator-runtime-identifier
Nov 25, 2025
Merged

Fix KeyNotFoundException when simulator lacks runtimeIdentifier or version#1501
simonrozsival merged 9 commits intomainfrom
copilot/fix-simulator-runtime-identifier

Conversation

Copy link
Contributor

Copilot AI commented Nov 19, 2025

Fix: Skip Simulators Without runtimeIdentifier ✅

Fixed the issue where SimulatorsCommand.IsInstalled() throws KeyNotFoundException when encountering simulator entries without a runtimeIdentifier or version property in the JSON output from xcrun simctl runtime list -j.

Checklist:

  • Understand the issue and locate the problematic code
  • Implement fix to check for runtimeIdentifier property existence before accessing it
  • Also check for version property existence (review feedback)
  • Remove tests as requested (review feedback)
  • Remove nuget.exe and prevent future commits (review feedback)
  • Build and test the changes (37 CLI tests passed)

Changes Made:

Modified SimulatorsCommand.cs:

  • Line 242: Added check for runtimeIdentifier using TryGetProperty() - entries without this property are skipped
  • Line 250: Added check for version property using TryGetProperty() - returns null if missing
  • Added explanatory comments for both checks

Modified .gitignore:

  • Added .nuget/nuget.exe to prevent accidental commits of the NuGet executable

Test Results:

  • ✅ 37 CLI tests passed (original baseline)
  • ✅ Production code fix remains in place

Fixes #1500

Original prompt

This section details on the original issue you should resolve

<issue_title>[apple] SimulatorsCommand.IsInstalled throws when a simulator does not have runtimeIdentifier</issue_title>
<issue_description>Xharness throws when it encounters a Simulator JSON without runtimeIdentifier. From failing MAUI CI build:

2025-11-19T10:47:01.7180900Z �[40m�[37mdbug�[39m�[22m�[49m: 
2025-11-19T10:47:01.7181210Z       
2025-11-19T10:47:01.7181590Z �[40m�[37mdbug�[39m�[22m�[49m: Running xcrun simctl runtime list -j
2025-11-19T10:47:01.7181870Z       
2025-11-19T10:47:02.1123360Z �[40m�[37mdbug�[39m�[22m�[49m: Process xcrun exited with 0
2025-11-19T10:47:02.1124250Z       
2025-11-19T10:47:02.1129860Z �[40m�[37mdbug�[39m�[22m�[49m: Listing runtime disk images via returned: {
2025-11-19T10:47:02.1130480Z         "1F039DDE-73B1-4BF2-9FE0-7B089D0ABE5E" : {
2025-11-19T10:47:02.1130900Z           "build" : "23J352",
2025-11-19T10:47:02.1131300Z           "deletable" : true,
2025-11-19T10:47:02.1131620Z           "identifier" : "1F039DDE-73B1-4BF2-9FE0-7B089D0ABE5E",
2025-11-19T10:47:02.1131960Z           "kind" : "Patchable Cryptex Disk Image",
2025-11-19T10:47:02.1132260Z           "mountPath" : "\/Library\/Developer\/CoreSimulator\/Volumes\/tvOS_23J352",
2025-11-19T10:47:02.1132640Z           "parentMountPath" : "\/System\/Library\/AssetsV2\/com_apple_MobileAsset_appleTVOSSimulatorRuntime\/1ceae9b3248d27ac43d7700bd6fdb3780d812fda.asset\/AssetData",
2025-11-19T10:47:02.1133150Z           "path" : "\/System\/Library\/AssetsV2\/com_apple_MobileAsset_appleTVOSSimulatorRuntime\/1ceae9b3248d27ac43d7700bd6fdb3780d812fda.asset\/AssetData\/Restore\/AppleTVOSSimulatorRuntime_Cryptex.dmg",
2025-11-19T10:47:02.1133610Z           "platformIdentifier" : "com.apple.platform.appletvsimulator",
2025-11-19T10:47:02.1133980Z           "runtimeBundlePath" : "\/Library\/Developer\/CoreSimulator\/Volumes\/tvOS_23J352\/Library\/Developer\/CoreSimulator\/Profiles\/Runtimes\/tvOS 26.0.simruntime",
2025-11-19T10:47:02.1134380Z           "runtimeIdentifier" : "com.apple.CoreSimulator.SimRuntime.tvOS-26-0",
2025-11-19T10:47:02.1134670Z           "signatureState" : "Verified",
2025-11-19T10:47:02.1134960Z           "sizeBytes" : 4813964979,
2025-11-19T10:47:02.1135200Z           "state" : "Ready",
2025-11-19T10:47:02.1135480Z           "supportedArchitectures" : [
2025-11-19T10:47:02.1135720Z             "x86_64",
2025-11-19T10:47:02.1135950Z             "arm64"
2025-11-19T10:47:02.1136210Z           ],
2025-11-19T10:47:02.1136430Z           "version" : "26.0"
2025-11-19T10:47:02.1136700Z         },
2025-11-19T10:47:02.1137200Z         "2A448011-F93C-427C-A6F2-CF5EFA39290F" : {
2025-11-19T10:47:02.1137500Z           "build" : "23A343",
2025-11-19T10:47:02.1137730Z           "deletable" : true,
2025-11-19T10:47:02.1138030Z           "identifier" : "2A448011-F93C-427C-A6F2-CF5EFA39290F",
2025-11-19T10:47:02.1138310Z           "kind" : "Patchable Cryptex Disk Image",
2025-11-19T10:47:02.1138600Z           "lastUsedAt" : "2025-11-19T10:40:50Z",
2025-11-19T10:47:02.1138940Z           "mountPath" : "\/Library\/Developer\/CoreSimulator\/Volumes\/iOS_23A343",
2025-11-19T10:47:02.1139320Z           "parentMountPath" : "\/System\/Library\/AssetsV2\/com_apple_MobileAsset_iOSSimulatorRuntime\/12c8e05d7212c19ae52f0d8db2cb46893aaca5aa.asset\/AssetData",
2025-11-19T10:47:02.1139800Z           "path" : "\/System\/Library\/AssetsV2\/com_apple_MobileAsset_iOSSimulatorRuntime\/12c8e05d7212c19ae52f0d8db2cb46893aaca5aa.asset\/AssetData\/Restore\/iOSSimulatorRuntime_Cryptex.dmg",
2025-11-19T10:47:02.1140210Z           "platformIdentifier" : "com.apple.platform.iphonesimulator",
2025-11-19T10:47:02.1140590Z           "runtimeBundlePath" : "\/Library\/Developer\/CoreSimulator\/Volumes\/iOS_23A343\/Library\/Developer\/CoreSimulator\/Profiles\/Runtimes\/iOS 26.0.simruntime",
2025-11-19T10:47:02.1141000Z           "runtimeIdentifier" : "com.apple.CoreSimulator.SimRuntime.iOS-26-0",
2025-11-19T10:47:02.1141280Z           "signatureState" : "Verified",
2025-11-19T10:47:02.1141570Z           "sizeBytes" : 10020150810,
2025-11-19T10:47:02.1141820Z           "state" : "Ready",
2025-11-19T10:47:02.1142100Z           "supportedArchitectures" : [
2025-11-19T10:47:02.1142340Z             "x86_64",
2025-11-19T10:47:02.1142570Z             "arm64"
2025-11-19T10:47:02.1142820Z           ],
2025-11-19T10:47:02.1143080Z           "version" : "26.0"
2025-11-19T10:47:02.1143330Z         },
2025-11-19T10:47:02.1143590Z         "8728D520-0F86-4227-AE03-716249BBB18C" : {
2025-11-19T10:47:02.1143880Z           "deletable" : true,
2025-11-19T10:47:02.1144150Z           "identifier" : "8728D520-0F86-4227-AE03-716249BBB18C",
2025-11-19T10:47:02.1144610Z           "kind" : "Cryptex Disk Image",
2025-11-19T10:47:02.1144890Z          ...

</details>

- Fixes dotnet/xharness#1500

<!-- START COPILOT CODING AGENT TIPS -->
---

💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey).

Copilot AI and others added 3 commits November 19, 2025 13:06
…dd tests

Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>
Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>
Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix SimulatorsCommand.IsInstalled for missing runtimeIdentifier Fix KeyNotFoundException when simulator lacks runtimeIdentifier Nov 19, 2025
Copilot AI requested a review from simonrozsival November 19, 2025 13:14
Copilot AI and others added 2 commits November 19, 2025 13:28
Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>
…rsion

Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 19, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • netcorenativeassets.blob.core.windows.net
    • Triggering command: dotnet build src/Microsoft.DotNet.XHarness.CLI/Microsoft.DotNet.XHarness.CLI.csproj --no-restore (dns block)
  • securitytools.pkgs.visualstudio.com
    • Triggering command: /opt/hostedtoolcache/CodeQL/2.23.3/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title Fix KeyNotFoundException when simulator lacks runtimeIdentifier Fix KeyNotFoundException when simulator lacks runtimeIdentifier or version Nov 19, 2025
Copilot AI requested a review from simonrozsival November 19, 2025 13:34
Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>
Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>
@simonrozsival simonrozsival marked this pull request as ready for review November 19, 2025 13:54
@simonrozsival
Copy link
Member

/cc @rmarinho @kotlarmilos @akoeplinger

@simonrozsival simonrozsival enabled auto-merge (squash) November 25, 2025 13:59
@simonrozsival
Copy link
Member

There is a failing tests in Helix related to permissions. I'm quite sure it's not related to this PR, is that just a flaky test?

[09:11:03] dbug: Running /Applications/Xcode_14.3.app/Contents/Developer/usr/bin/simctl
[09:11:03] dbug: Process simctl exited with 0
[09:11:03] dbug: 
[09:11:03] dbug: Running /Applications/Xcode_14.3.app/Contents/Developer/usr/bin/simctl
[09:11:03] dbug: An error was encountered processing the command (domain=NSCocoaErrorDomain, code=513):
[09:11:03] dbug: You don’t have permission to save the file “71AF6439-A412-4117-91B4-7B438AAB3E7A” in the folder “CoreSimulator”.
[09:11:03] dbug: You don’t have permission.
[09:11:03] dbug: To view or change permissions, select the item in the Finder and choose File > Get Info.
[09:11:03] dbug: Underlying error (domain=NSPOSIXErrorDomain, code=13):
[09:11:03] dbug: The operation couldn’t be completed. Permission denied
[09:11:03] dbug: Permission denied
[09:11:03] dbug: Process simctl exited with 1
[09:11:03] dbug: 
[09:11:03] dbug: Running /Applications/Xcode_14.3.app/Contents/Developer/usr/bin/simctl
[09:11:04] dbug: An error was encountered processing the command (domain=com.apple.CoreSimulator.SimError, code=405):
[09:11:04] dbug: Unable to shutdown device in current state: Shutdown
[09:11:04] dbug: Process simctl exited with 149
[09:11:04] dbug: Booting the simulator to create TCC.db
[09:11:04] dbug: 
[09:11:04] dbug: Running /Applications/Xcode_14.3.app/Contents/Developer/usr/bin/simctl
[09:11:04] dbug: An error was encountered processing the command (domain=NSCocoaErrorDomain, code=513):
[09:11:04] dbug: You don’t have permission to save the file “71AF6439-A412-4117-91B4-7B438AAB3E7A” in the folder “CoreSimulator”.
[09:11:04] dbug: You don’t have permission.
[09:11:04] dbug: To view or change permissions, select the item in the Finder and choose File > Get Info.
[09:11:04] dbug: Underlying error (domain=NSPOSIXErrorDomain, code=13):
[09:11:04] dbug: The operation couldn’t be completed. Permission denied
[09:11:04] dbug: Permission denied
[09:11:04] dbug: Process simctl exited with 1
[09:11:04] dbug: Waiting for simulator to create TCC.db... 59
[09:11:04] dbug: Waiting for simulator to create TCC.db... 59
[09:11:04] dbug: Waiting for simulator to create TCC.db... 59
[09:11:05] dbug: Waiting for simulator to create TCC.db... 59
[09:11:05] dbug: Waiting for simulator to create TCC.db... 58

@kotlarmilos
Copy link
Member

This happened here as well #1504, so it isn't related to this PR

@kotlarmilos
Copy link
Member

/ba-g #1509

@simonrozsival simonrozsival merged commit 06be2b9 into main Nov 25, 2025
15 of 17 checks passed
@simonrozsival simonrozsival deleted the copilot/fix-simulator-runtime-identifier branch November 25, 2025 18:14
@kotlarmilos
Copy link
Member

/backport to release/10.0

@github-actions
Copy link

Started backporting to release/10.0 (link to workflow run)

kotlarmilos pushed a commit to kotlarmilos/xharness that referenced this pull request Mar 16, 2026
…rsion (dotnet#1501)

* Initial plan

* Fix SimulatorsCommand to skip entries without runtimeIdentifier and add tests

Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>

* Completed fix for SimulatorsCommand runtimeIdentifier issue

Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>

* Remove accidentally committed nuget.exe

Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>

* Address review feedback: check version property and improve tests

Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>

* Fix KeyNotFoundException when simulator lacks runtimeIdentifier or version

Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>

* Remove SimulatorsCommandTests as requested

Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>

* Remove nuget.exe and add to .gitignore

Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>

* Remove unnecessary changes from gitignore

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>
Co-authored-by: Simon Rozsival <simon@rozsival.com>
kotlarmilos pushed a commit to kotlarmilos/xharness that referenced this pull request Mar 16, 2026
…rsion (dotnet#1501)

* Initial plan

* Fix SimulatorsCommand to skip entries without runtimeIdentifier and add tests

Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>

* Completed fix for SimulatorsCommand runtimeIdentifier issue

Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>

* Remove accidentally committed nuget.exe

Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>

* Address review feedback: check version property and improve tests

Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>

* Fix KeyNotFoundException when simulator lacks runtimeIdentifier or version

Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>

* Remove SimulatorsCommandTests as requested

Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>

* Remove nuget.exe and add to .gitignore

Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>

* Remove unnecessary changes from gitignore

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>
Co-authored-by: Simon Rozsival <simon@rozsival.com>
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.

[apple] SimulatorsCommand.IsInstalled throws when a simulator does not have runtimeIdentifier

3 participants