Skip to content

[UIKit] Enable nullability and clean up UIGraphics.#24655

Merged
rolfbjarne merged 2 commits intomainfrom
dev/rolf/uikit-nullability-uigraphics-11
Feb 10, 2026
Merged

[UIKit] Enable nullability and clean up UIGraphics.#24655
rolfbjarne merged 2 commits intomainfrom
dev/rolf/uikit-nullability-uigraphics-11

Conversation

@rolfbjarne
Copy link
Copy Markdown
Member

This is file 11 of 30 files with nullability disabled in UIKit.

  • Enable nullability (#nullable enable).
  • Add nullable annotations (UIImage?, CGContext?, NSDictionary?, CGPDFInfo?).
  • Fix null reference return in UIImage.Scale methods caused by nullable GetImageFromCurrentImageContext return type.
  • Improve XML documentation comments: remove 'To be added.' placeholders, fix formatting, add missing docs for BeginImageContextWithOptions, EndPDFContext, and other members, add 'see cref' references, remove empty and elements, fix element ordering (summary before param), correct PDF context method remarks to reference EndPDFContext instead of EndImageContext.

Contributes towards #17285.

This is file 11 of 30 files with nullability disabled in UIKit.

* Enable nullability (#nullable enable).
* Add nullable annotations (UIImage?, CGContext?, NSDictionary?, CGPDFInfo?).
* Fix null reference return in UIImage.Scale methods caused by nullable GetImageFromCurrentImageContext return type.
* Improve XML documentation comments: remove 'To be added.' placeholders, fix formatting, add missing docs for BeginImageContextWithOptions, EndPDFContext, and other members, add 'see cref' references, remove empty <value> and <remarks> elements, fix element ordering (summary before param), correct PDF context method remarks to reference EndPDFContext instead of EndImageContext.

Contributes towards #17285.
Copy link
Copy Markdown
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 continues the UIKit nullability enablement work by switching UIGraphics to #nullable enable, updating a few related APIs/annotations (including UIImage.Scale), and cleaning up/improving XML documentation so the doc build no longer needs known-failure exceptions.

Changes:

  • Enable nullable reference types in src/UIKit/UIGraphics.cs and update several APIs to return/accept nullable values where appropriate.
  • Fix UIImage.Scale to propagate possible null results from UIGraphics.GetImageFromCurrentImageContext ().
  • Improve/normalize XML documentation and remove corresponding entries from Documentation.KnownFailures.txt.

Reviewed changes

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

File Description
tests/cecil-tests/Documentation.KnownFailures.txt Removes known doc-generation failures now that UIGraphics XML docs are improved.
src/UIKit/UIImage.cs Makes Scale overloads return UIImage? to reflect possible null results from UIGraphics image-context extraction.
src/UIKit/UIGraphics.cs Enables nullability, updates return/parameter nullability, and performs significant XML doc cleanup/expansion.
Comments suppressed due to low confidence (3)

src/UIKit/UIGraphics.cs:185

  • With nullable enabled, SetPDFContextURL should validate the non-nullable url parameter before using url.Handle. Otherwise a null value will result in a NullReferenceException; prefer throwing ArgumentNullException early.
		public static void SetPDFContextURL (NSUrl url, CGRect rect)
		{
			UIGraphicsSetPDFContextURLForRect (url.Handle, rect);
			GC.KeepAlive (url);

src/UIKit/UIGraphics.cs:266

  • With nullable enabled, BeginPDFPage (CGRect, NSDictionary) should validate the non-nullable pageInfo parameter before using pageInfo.Handle. Otherwise a null value will result in a NullReferenceException; prefer throwing ArgumentNullException early.
		public static void BeginPDFPage (CGRect bounds, NSDictionary pageInfo)
		{
			UIGraphicsBeginPDFPageWithInfo (bounds, pageInfo.Handle);
			GC.KeepAlive (pageInfo);

src/UIKit/UIGraphics.cs:337

  • With nullable enabled, PushContext should validate the non-nullable ctx parameter before dereferencing it. As-is, passing null will throw a NullReferenceException when accessing ctx.Handle; prefer throwing ArgumentNullException (for example via ArgumentNullException.ThrowIfNull (ctx)).
		public static void PushContext (CGContext ctx)
		{
			UIGraphicsPushContext (ctx.Handle);
			GC.KeepAlive (ctx);

Comment thread src/UIKit/UIGraphics.cs
/// <para>This function can only be invoked from the UI thread.</para>
/// </remarks>
public static void BeginPDFContext (NSMutableData data, CGRect bounds, NSDictionary? documentInfo)
{
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

With nullable enabled, BeginPDFContext (NSMutableData ...) should validate the non-nullable data parameter before accessing data.Handle. Passing null currently results in a NullReferenceException; prefer throwing ArgumentNullException early.

Suggested change
{
{
System.ArgumentNullException.ThrowIfNull (data);

Copilot uses AI. Check for mistakes.
Comment thread src/UIKit/UIImage.cs
[UnsupportedOSPlatform ("tvos17.0")]
[UnsupportedOSPlatform ("maccatalyst17.0")]
public UIImage Scale (CGSize newSize, nfloat scaleFactor)
public UIImage? Scale (CGSize newSize, nfloat scaleFactor)
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

Scale now returns UIImage?, but the XML documentation still says "The scaled image." without mentioning that the return value can be null (via UIGraphics.GetImageFromCurrentImageContext ()). Please update the <returns> text to document the possible null return.

Copilot uses AI. Check for mistakes.
Comment thread src/UIKit/UIImage.cs
[UnsupportedOSPlatform ("tvos17.0")]
[UnsupportedOSPlatform ("maccatalyst17.0")]
public UIImage Scale (CGSize newSize)
public UIImage? Scale (CGSize newSize)
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

Same as the other overload: this Scale method now returns UIImage?, but the XML documentation does not mention that null can be returned. Please update the <returns> docs accordingly.

Copilot uses AI. Check for mistakes.
Comment thread src/UIKit/UIGraphics.cs Outdated
/// <remarks>
/// <para>UIKit keeps a stack of image contexts. This method creates a new image context, makes it the default and places it at the top of the graphic context stack.</para>
/// <para>To restore the previous graphics context, call the <see cref="EndImageContext" /> method.</para>
/// <para>You can get the current context by calling the <see cref="GetImageFromCurrentImageContext" /> method.</para>
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

The remarks say "You can get the current context by calling GetImageFromCurrentImageContext", but that API returns an image (not a graphics context). This looks like a documentation bug; please adjust the wording to refer to getting the current image from the image context.

Suggested change
/// <para>You can get the current context by calling the <see cref="GetImageFromCurrentImageContext" /> method.</para>
/// <para>You can get the current image from the current image context by calling the <see cref="GetImageFromCurrentImageContext" /> method.</para>

Copilot uses AI. Check for mistakes.
Comment thread src/UIKit/UIGraphics.cs Outdated
/// <remarks>
/// <para>UIKit keeps a stack of image contexts. This method creates a new image context, makes it the default and places it at the top of the graphic context stack.</para>
/// <para>To restore the previous graphics context, call the <see cref="EndImageContext" /> method.</para>
/// <para>You can get the current context by calling the <see cref="GetImageFromCurrentImageContext" /> method.</para>
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

Same documentation issue as BeginImageContext: the remarks state that GetImageFromCurrentImageContext returns the current context, but it returns an image. Please correct this wording here as well.

Suggested change
/// <para>You can get the current context by calling the <see cref="GetImageFromCurrentImageContext" /> method.</para>
/// <para>You can get the image from the current image context by calling the <see cref="GetImageFromCurrentImageContext" /> method.</para>

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

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne rolfbjarne enabled auto-merge (squash) February 10, 2026 11:51
@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [PR Build #094b726] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: 094b7263c493cd5e7f7cb312ce70572b2e1dac22 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [CI Build #094b726] Build passed (Build packages) ✅

Pipeline on Agent
Hash: 094b7263c493cd5e7f7cb312ce70572b2e1dac22 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
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: 094b7263c493cd5e7f7cb312ce70572b2e1dac22 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [CI Build #094b726] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: 094b7263c493cd5e7f7cb312ce70572b2e1dac22 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

💻 [CI Build #094b726] Tests on macOS X64 - Mac Sonoma (14) passed 💻

All tests on macOS X64 - Mac Sonoma (14) passed.

Pipeline on Agent
Hash: 094b7263c493cd5e7f7cb312ce70572b2e1dac22 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

💻 [CI Build #094b726] Tests on macOS M1 - Mac Monterey (12) passed 💻

All tests on macOS M1 - Mac Monterey (12) passed.

Pipeline on Agent
Hash: 094b7263c493cd5e7f7cb312ce70572b2e1dac22 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

💻 [CI Build #094b726] Tests on macOS arm64 - Mac Sequoia (15) passed 💻

All tests on macOS arm64 - Mac Sequoia (15) passed.

Pipeline on Agent
Hash: 094b7263c493cd5e7f7cb312ce70572b2e1dac22 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

💻 [CI Build #094b726] Tests on macOS M1 - Mac Ventura (13) passed 💻

All tests on macOS M1 - Mac Ventura (13) passed.

Pipeline on Agent
Hash: 094b7263c493cd5e7f7cb312ce70572b2e1dac22 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

💻 [CI Build #094b726] Tests on macOS arm64 - Mac Tahoe (26) passed 💻

All tests on macOS arm64 - Mac Tahoe (26) passed.

Pipeline on Agent
Hash: 094b7263c493cd5e7f7cb312ce70572b2e1dac22 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

🚀 [CI Build #094b726] Test results 🚀

Test results

✅ All tests passed on VSTS: test results.

🎉 All 117 tests passed 🎉

Tests counts

✅ 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
✅ fsharp: All 4 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. [attempt 2] Html Report (VSDrops) Download
✅ linker: All 44 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ monotouch (iOS): All 9 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 11 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 9 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 9 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. [attempt 2] Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

Pipeline on Agent
Hash: 094b7263c493cd5e7f7cb312ce70572b2e1dac22 [PR build]

@rolfbjarne rolfbjarne merged commit 214065b into main Feb 10, 2026
47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants