Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] Adding Items to ObservableCollection from other UIThread in ListView Throws System.Runtime.InteropServices.COMException #27174

Open
LogishaSelvarajSF4525 opened this issue Jan 16, 2025 · 3 comments
Labels
area-controls-listview ListView and TableView platform/windows 🪟 s/triaged Issue has been reviewed s/try-latest-version Please try to reproduce the potential issue on the latest public version t/bug Something isn't working

Comments

@LogishaSelvarajSF4525
Copy link
Contributor

Description

Description

In .NET MAUI, a System.Runtime.InteropServices.COMException is encountered when adding data to a shared ObservableCollection (staticData.TestCollection) from a background thread. This problem is specific to the Windows platform, as ObservableCollection requires all operations to be performed on the same thread on which it was created, typically the UI thread, and does not support cross-thread modifications.

This issue occurs exclusively on the Windows platform and does not affect other platforms.

Note: While fixing this issue enable the following UITest in HostApp: Issue6472

In Windows,

Image

Steps to Reproduce

  1. Run the application with attached code on the Windows platform. MauiApp1.zip

Expected Behavior:

  • Items should be successfully added to the ObservableCollection without throwing any exceptions.
  • The ListView should update to display the new items added from the background thread.

Actual Behavior:

  • A runtime exception is thrown, indicating that the ObservableCollection cannot be modified from a thread other than the one it was created on.
  • The ListView does not update, and the application may crash depending on how the exception is handled.

Link to public reproduction project repository

No response

Version with bug

9.0.12 SR1.2

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

@LogishaSelvarajSF4525 LogishaSelvarajSF4525 added the t/bug Something isn't working label Jan 16, 2025
@LogishaSelvarajSF4525 LogishaSelvarajSF4525 changed the title [Windows] Adding Data to ObservableCollection from other UIThread Throws System.Runtime.InteropServices.COMException [Windows] Adding Items to ObservableCollection from other UIThread in ListView Throws System.Runtime.InteropServices.COMException Jan 16, 2025
@RoiChen001 RoiChen001 added s/triaged Issue has been reviewed s/try-latest-version Please try to reproduce the potential issue on the latest public version platform/windows 🪟 labels Jan 17, 2025
Copy link
Contributor

Hi @LogishaSelvarajSF4525. We have added the "s/try-latest-version" label to this issue, which indicates that we'd like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version.

You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository.

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@RoiChen001
Copy link

I verified this issue on the latest 17.13 Preview 2.1(9.0.30 & 9.0.12) Windows platform, but no exception was thrown.

@nivetha-nagalingam
Copy link
Contributor

nivetha-nagalingam commented Jan 17, 2025

In Issue 6994 from HostApp, the same exception System.Runtime.InteropServices.COMException was also occurring, as detailed in the file located at https://github.com/dotnet/maui/blob/main/src/Controls/tests/TestCases.HostApp/Issues/Issue6994.cs

ListViewCrash6994.mp4

@samhouts samhouts added the area-controls-listview ListView and TableView label Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-listview ListView and TableView platform/windows 🪟 s/triaged Issue has been reviewed s/try-latest-version Please try to reproduce the potential issue on the latest public version t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants