Skip to content

Conversation

@rolfbjarne
Copy link
Member

This is file 40 of 47 files with nullability disabled in Foundation.

  • Enabled nullable reference types.
  • Removed four SupportedOSPlatform attributes without version numbers.
  • Replaced 'To be added.' XML comments with proper documentation.
  • Added XML documentation for all public and protected members.
  • Used ArgumentNullException.ThrowIfNull for parameter validation.
  • Fixed XML comment formatting and added see cref attributes.
  • Made ObjectForKey return nullable TValue? since keys may not exist.
  • Made TryGetValue parameter nullable with NotNullWhen(true) attribute.
  • Kept IDictionary interface implementations non-nullable per .NET contract.
  • Used KeyNotFoundException when indexer accesses missing keys.
  • Fixed IEnumerator implementations to skip null values in enumeration.
  • Changed empty array initialization from 'new TValue[]{}' to '[]'.
  • Remove some dead code.
  • Add a few more tests.

Contributes towards #17285.

This is file 40 of 47 files with nullability disabled in Foundation.

* Enabled nullable reference types.
* Removed four SupportedOSPlatform attributes without version numbers.
* Replaced 'To be added.' XML comments with proper documentation.
* Added XML documentation for all public and protected members.
* Used ArgumentNullException.ThrowIfNull for parameter validation.
* Fixed XML comment formatting and added see cref attributes.
* Made ObjectForKey return nullable TValue? since keys may not exist.
* Made TryGetValue parameter nullable with NotNullWhen(true) attribute.
* Kept IDictionary interface implementations non-nullable per .NET contract.
* Used KeyNotFoundException when indexer accesses missing keys.
* Fixed IEnumerator implementations to skip null values in enumeration.
* Changed empty array initialization from 'new TValue[]{}' to '[]'.
* Remove some dead code.
* Add a few more tests.

Contributes towards #17285.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enables nullable reference types for NSMutableDictionary<TKey, TValue>, which is file 40 of 47 in the Foundation nullability migration effort. The changes improve type safety by making nullability explicit in method signatures, particularly for methods that can return null for missing keys like ObjectForKey. The PR also improves the indexer behavior to throw KeyNotFoundException for missing keys (aligning with .NET conventions), replaces placeholder XML documentation with comprehensive summaries, and modernizes parameter validation using ArgumentNullException.ThrowIfNull.

Key changes:

  • Made ObjectForKey return TValue? (nullable) since keys may not exist in the dictionary
  • Changed public indexer getter to throw KeyNotFoundException for missing keys instead of returning null
  • Added comprehensive XML documentation for all public members

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/Foundation/NSMutableDictionary_2.cs Enabled nullable reference types, updated method signatures for nullability, replaced placeholder XML docs with comprehensive documentation, modernized parameter validation, changed indexer to throw KeyNotFoundException for missing keys
tests/monotouch-test/Foundation/NSMutableDictionary2Test.cs Added comprehensive tests for missing key access behavior, testing ObjectForKey, TryGetValue, ContainsKey, indexer, and IDictionary interface behavior
tests/cecil-tests/Documentation.KnownFailures.txt Removed entries for methods that now have proper XML documentation

{
return TryGetValue (key, out value);
var result = TryGetValue (key, out var nullableValue);
value = nullableValue!;
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The coding guidelines state "Don't ever use ! to handle null!" The null-forgiving operator should be avoided. Instead, this could be rewritten to avoid the null-forgiving operator, for example by using a conditional assignment or restructuring the code.

Copilot generated this review using guidance from repository custom instructions.
Comment on lines +372 to +374
// But accessing via IDictionary interface should return null
IDictionary<NSString, NSDate> idict = dict;
Assert.IsNull (idict [keyMissing], "missing key via interface");
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test expects the IDictionary indexer to return null for missing keys, but the implementation at line 380 calls the public indexer which throws KeyNotFoundException. According to the .NET IDictionary interface contract, the indexer getter should throw KeyNotFoundException when the key is not found, not return null. Either this test assertion is incorrect, or the IDictionary indexer implementation should be changed to return ObjectForKey directly to maintain backwards compatibility (though that would violate .NET conventions).

Copilot uses AI. Check for mistakes.
Comment on lines +405 to +407
// But IDictionary indexer should return null
IDictionary<NSString, NSDate> idict = dict;
Assert.IsNull (idict [keyMissing], "IDictionary indexer missing");
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test expects the IDictionary indexer to return null for missing keys, but the implementation at line 380 calls the public indexer which throws KeyNotFoundException. According to the .NET IDictionary interface contract, the indexer getter should throw KeyNotFoundException when the key is not found, not return null. Either this test assertion is incorrect, or the IDictionary indexer implementation should be changed to return ObjectForKey directly to maintain backwards compatibility (though that would violate .NET conventions).

Copilot uses AI. Check for mistakes.
Comment on lines +426 to +427
IDictionary<NSString, NSDate> idict = dict;
Assert.IsNull (idict [keyMissing], "IDictionary indexer");
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test expects the IDictionary indexer to return null for missing keys, but the implementation at line 380 calls the public indexer which throws KeyNotFoundException. According to the .NET IDictionary interface contract, the indexer getter should throw KeyNotFoundException when the key is not found, not return null. Either this test assertion is incorrect, or the IDictionary indexer implementation should be changed to return ObjectForKey directly to maintain backwards compatibility (though that would violate .NET conventions).

Copilot uses AI. Check for mistakes.
@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [PR Build #7f9f0c3] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: 7f9f0c39e22276e8ad7b749db13ad45a2fcc4c65 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build #7f9f0c3] Build passed (Build packages) ✅

Pipeline on Agent
Hash: 7f9f0c39e22276e8ad7b749db13ad45a2fcc4c65 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: 7f9f0c39e22276e8ad7b749db13ad45a2fcc4c65 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build #7f9f0c3] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: 7f9f0c39e22276e8ad7b749db13ad45a2fcc4c65 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

❌ [CI Build #7f9f0c3] Tests on macOS X64 - Mac Sonoma (14) failed ❌

Failed tests are:

  • monotouch-test

Pipeline on Agent
Hash: 7f9f0c39e22276e8ad7b749db13ad45a2fcc4c65 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

❌ [CI Build #7f9f0c3] Tests on macOS M1 - Mac Monterey (12) failed ❌

Failed tests are:

  • monotouch-test

Pipeline on Agent
Hash: 7f9f0c39e22276e8ad7b749db13ad45a2fcc4c65 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

❌ [CI Build #7f9f0c3] Tests on macOS arm64 - Mac Sequoia (15) failed ❌

Failed tests are:

  • monotouch-test

Pipeline on Agent
Hash: 7f9f0c39e22276e8ad7b749db13ad45a2fcc4c65 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

❌ [CI Build #7f9f0c3] Tests on macOS M1 - Mac Ventura (13) failed ❌

Failed tests are:

  • monotouch-test

Pipeline on Agent
Hash: 7f9f0c39e22276e8ad7b749db13ad45a2fcc4c65 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

❌ [CI Build #7f9f0c3] Tests on macOS arm64 - Mac Tahoe (26) failed ❌

Failed tests are:

  • monotouch-test

Pipeline on Agent
Hash: 7f9f0c39e22276e8ad7b749db13ad45a2fcc4c65 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

🔥 [CI Build #7f9f0c3] Test results 🔥

Test results

❌ Tests failed on VSTS: test results

0 tests crashed, 40 tests failed, 77 tests passed.

Failures

❌ fsharp tests

1 tests failed, 3 tests passed.

Failed tests

  • fsharp/tvOS - simulator/Debug: Crashed

Html Report (VSDrops) Download

❌ linker tests

1 tests failed, 43 tests passed.

Failed tests

  • dont link/tvOS - simulator/Debug: Crashed

Html Report (VSDrops) Download

❌ monotouch tests (iOS)

9 tests failed, 0 tests passed.

Failed tests

  • monotouch-test/iOS - simulator/Debug: Failed
  • monotouch-test/iOS - simulator/Debug (LinkSdk): Failed
  • monotouch-test/iOS - simulator/Debug (static registrar): Failed
  • monotouch-test/iOS - simulator/Release (all optimizations): Failed
  • monotouch-test/iOS - simulator/Debug (managed static registrar): Failed
  • monotouch-test/iOS - simulator/Release (managed static registrar, all optimizations): Failed
  • monotouch-test/iOS - simulator/Release (NativeAOT, x64): Failed
  • monotouch-test/iOS - simulator/Debug (interpreter): Failed
  • monotouch-test/iOS - simulator/Release (interpreter): Failed

Html Report (VSDrops) Download

❌ monotouch tests (MacCatalyst)

11 tests failed, 0 tests passed.

Failed tests

  • monotouch-test/Mac Catalyst/Debug: Failed (Test run failed.
    Tests run: 3592 Passed: 3372 Inconclusive: 19 Failed: 5 Ignored: 215)
  • monotouch-test/Mac Catalyst/Debug (managed static registrar): Failed (Test run failed.
    Tests run: 3589 Passed: 3364 Inconclusive: 13 Failed: 5 Ignored: 220)
  • monotouch-test/Mac Catalyst/Debug (static registrar): Failed (Test run failed.
    Tests run: 3589 Passed: 3364 Inconclusive: 13 Failed: 5 Ignored: 220)
  • monotouch-test/Mac Catalyst/Release (managed static registrar): Failed (Test run failed.
    Tests run: 3589 Passed: 3363 Inconclusive: 20 Failed: 5 Ignored: 221)
  • monotouch-test/Mac Catalyst/Release (managed static registrar, all optimizations): Failed (Test run failed.
    Tests run: 3589 Passed: 3352 Inconclusive: 13 Failed: 5 Ignored: 232)
  • monotouch-test/Mac Catalyst/Release (NativeAOT): Failed (Test run failed.
    Tests run: 3589 Passed: 3348 Inconclusive: 13 Failed: 5 Ignored: 236)
  • monotouch-test/Mac Catalyst/Release (NativeAOT, x64): Failed (Test run failed.
    Tests run: 3589 Passed: 3348 Inconclusive: 13 Failed: 5 Ignored: 236)
  • monotouch-test/Mac Catalyst/Release (static registrar): Failed (Test run failed.
    Tests run: 3589 Passed: 3358 Inconclusive: 13 Failed: 5 Ignored: 226)
  • monotouch-test/Mac Catalyst/Release (static registrar, all optimizations): Failed (Test run failed.
    Tests run: 3589 Passed: 3352 Inconclusive: 13 Failed: 5 Ignored: 232)
  • monotouch-test/Mac Catalyst/Debug (interpreter): Failed (Test run failed.
    Tests run: 3592 Passed: 3363 Inconclusive: 13 Failed: 5 Ignored: 224)
  • monotouch-test/Mac Catalyst/Release (interpreter): Failed (Test run failed.
    Tests run: 3589 Passed: 3356 Inconclusive: 13 Failed: 5 Ignored: 228)

Html Report (VSDrops) Download

❌ monotouch tests (macOS)

9 tests failed, 0 tests passed.

Failed tests

  • monotouch-test/macOS/Debug: Failed (Test run failed.
    Tests run: 3558 Passed: 3309 Inconclusive: 7 Failed: 5 Ignored: 244)
  • monotouch-test/macOS/Debug (managed static registrar): Failed (Test run failed.
    Tests run: 3555 Passed: 3366 Inconclusive: 7 Failed: 5 Ignored: 184)
  • monotouch-test/macOS/Debug (static registrar): Failed (Test run failed.
    Tests run: 3555 Passed: 3367 Inconclusive: 7 Failed: 5 Ignored: 183)
  • monotouch-test/macOS/Release (managed static registrar): Failed (Test run failed.
    Tests run: 3555 Passed: 3365 Inconclusive: 7 Failed: 5 Ignored: 185)
  • monotouch-test/macOS/Release (managed static registrar, all optimizations): Failed (Test run failed.
    Tests run: 3555 Passed: 3362 Inconclusive: 7 Failed: 5 Ignored: 188)
  • monotouch-test/macOS/Release (NativeAOT): Failed (Test run failed.
    Tests run: 3554 Passed: 3354 Inconclusive: 7 Failed: 5 Ignored: 195)
  • monotouch-test/macOS/Release (NativeAOT, x64): Failed (Test run failed.
    Tests run: 3554 Passed: 3355 Inconclusive: 7 Failed: 5 Ignored: 194)
  • monotouch-test/macOS/Release (static registrar): Failed (Test run failed.
    Tests run: 3555 Passed: 3365 Inconclusive: 7 Failed: 5 Ignored: 185)
  • monotouch-test/macOS/Release (static registrar, all optimizations): Failed (Test run failed.
    Tests run: 3555 Passed: 3363 Inconclusive: 7 Failed: 5 Ignored: 187)

Html Report (VSDrops) Download

❌ monotouch tests (tvOS)

9 tests failed, 0 tests passed.

Failed tests

  • monotouch-test/tvOS - simulator/Debug: Failed
  • monotouch-test/tvOS - simulator/Debug (LinkSdk): Failed
  • monotouch-test/tvOS - simulator/Debug (static registrar): Failed
  • monotouch-test/tvOS - simulator/Release (all optimizations): Failed
  • monotouch-test/tvOS - simulator/Debug (managed static registrar): Failed
  • monotouch-test/tvOS - simulator/Release (managed static registrar, all optimizations): Failed
  • monotouch-test/tvOS - simulator/Release (NativeAOT, x64): Failed
  • monotouch-test/tvOS - simulator/Debug (interpreter): Failed
  • monotouch-test/tvOS - simulator/Release (interpreter): Failed

Html Report (VSDrops) Download

Successes

✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 4 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ windows: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

Pipeline on Agent
Hash: 7f9f0c39e22276e8ad7b749db13ad45a2fcc4c65 [PR build]

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.

4 participants