Fix NullReferenceException and crash in ManifestExtensions#182
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes robustness issues in Xamarin.MacDev manifest parsing/extensions to avoid crashes when expected plist structures or device family values are missing/unknown.
Changes:
- Avoids
NullReferenceExceptionin WatchKit bundle identifier getters/setters whenNSExtensionAttributesis absent. - Prevents
ArgumentOutOfRangeExceptionwhen parsing unknown numericUIDeviceFamilyentries by logging and using a fallback. - Adds NUnit coverage for the above scenarios.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| Xamarin.MacDev/ManifestExtensions.cs | Adds null-guarding for NSExtensionAttributes access and changes unknown numeric device-family handling to warn + fallback. |
| tests/ManifestExtensionsTests.cs | Adds tests for missing extension dictionaries and unknown/known UIDeviceFamily parsing behavior. |
- GetWKAppBundleIdentifier: handle null from GetNSExtensionAttributes. - SetWKAppBundleIdentifier: auto-create NSExtension/NSExtensionAttributes structure when setting a non-empty value (avoid silent no-op). - ParseDeviceFamilyFromNumber → TryParseDeviceFamilyFromNumber: unknown device family numbers are now logged and skipped (not coerced to IPhone), consistent with how the string parser already handles unknown values. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
7d5ea0a to
214ee0c
Compare
Changed 'Skipped unknown device family' to 'Ignoring unrecognized device family number' to make it clear the value is not mapped to any family and is simply discarded. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
rolfbjarne
approved these changes
Jun 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
Fixes two bugs in
ManifestExtensions:NullReferenceException in
GetWKAppBundleIdentifier/SetWKAppBundleIdentifier— these methods calledGetNSExtensionAttributes()which can return null, then immediately dereferenced the result without a null check.ArgumentOutOfRangeException in
ParseDeviceFamilyFromNumber— throws for unknown device family numbers (e.g. from newer Xcode plists), crashingGetUIDeviceFamily. Now logs a warning and returns a safe fallback, consistent with how the string parser already handles unknown values.Testing
Added
ManifestExtensionsTestswith 6 tests covering both null/missing dictionary cases and unknown device family handling.