Skip to content

Conversation

@HarishwaranVijayakumar
Copy link
Contributor

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Issue Details

  • PickPhotosAsync throws an ObjectDisposedException when size or compression options are used.

Root Cause of the issue

  • The method ApplyMetadataAsync in ImageProcessor.windows.cs returns the same stream that was passed in. However, on iOS and Android, it returns a new stream. After ApplyMetadataAsync completes, the old stream is disposed. On Android and iOS, this is fine because a new stream is returned, so disposing the old one has no effect. But on Windows, since the same stream is returned and then disposed, accessing it afterward causes an exception.

Description of Change

  • Resource management improvement:
    • In ImageProcessor.shared.cs, updated the logic to only dispose outputStream if ApplyMetadataAsync returns a different stream, preventing unintended disposal on platforms (like Windows) where the same stream may be returned.

Issues Fixed

Fixes #32408

Tested the behaviour in the following platforms

  • - Windows
  • - Android
  • - iOS
  • - Mac

Output

Before After
BeforeFix.mp4
AfterFix.mp4

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Dec 2, 2025
@dotnet-policy-service
Copy link
Contributor

Hey there @@HarishwaranVijayakumar! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@dotnet-policy-service dotnet-policy-service bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Dec 2, 2025
@sheiksyedm sheiksyedm marked this pull request as ready for review December 2, 2025 11:45
Copilot AI review requested due to automatic review settings December 2, 2025 11:45
Copilot finished reviewing on behalf of sheiksyedm December 2, 2025 11:47
@sheiksyedm
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

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 fixes an ObjectDisposedException in PickPhotosAsync on Windows when using image size or compression options. The root cause was that ApplyMetadataAsync returns the same stream on Windows (and other platforms in error paths), but the code was unconditionally disposing the stream after the method call, making it unusable.

Key Changes:

  • Added a reference equality check before disposing outputStream after ApplyMetadataAsync
  • This prevents disposing a stream that's still needed when the same stream instance is returned
  • The fix applies to all platforms since they all can return the same stream in various scenarios

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PickPhotosAsync throws exception if image is modified.

2 participants