CommunityToolkit / CommunityToolkit/Maui
[BUG] App crash using Maui.Camera on Surface Go 2 and 3s (Windows)
- Dominant language
- C#
- Stars
- 2.7k
- Forks
- 500
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 7
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Did you read the "Reporting a bug" section on Contributing file?
- [x] I have read the "Reporting a bug" section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug
### Current Behavior
Taking a photo on a Surface Go 2 or 3 cause the app to crash immediately with the following Exception. It's worse on a Surface Go 2 then on a 3.
Exception:
System.Runtime.InteropServices.COMException: This object needs to be initialized before the requested operation can be carried out.
This object needs to be initialized before the requested operation can be carried out.
Stacktrace:
IReadOnlyDictionary MediaCapture.get_FrameSources()
/_/src/CommunityToolkit.Maui.Camera/CameraManager.windows.cs in async void d__22.MoveNext() at line 152:3
/_/src/CommunityToolkit.Maui.Camera/CameraManager.windows.cs in async void d__23.MoveNext() at line 132:3
/_/src/CommunityToolkit.Maui.Camera/Handlers/CameraViewHandler.shared.cs in async void CameraViewHandler.ConnectHandler(FrameworkElement platformView) at line 87:3
Called from: Task.cs in void Task.ThrowAsync(Exception exception, SynchronizationContext targetContext)+(object state) => { }
### Expected Behavior
The app should not crash.
May be related: https://github.com/CommunityToolkit/Maui/issues/2559 - although the current exception is different.
### Steps To Reproduce
The key to replicating is taking a photo on a Surface Go 2 and 3. The existing Toolkit code sample can be use to replicate.
### Link to public reproduction project repository
[Repo sample](https://github.com/CommunityToolkit/Maui/tree/main/samples)
### Environment
```markdown
- .NET MAUI CommunityToolkit:CommunityToolkit.Maui.Camera 5.0
- OS: Windows 11
- .NET MAUI: 10
```
### Anything else?
_No response_
Contributor guide
Research direction
Start with CameraManager.windows.cs at lines 132 and 152, then review CameraViewHandler.shared.cs at line 87 to trace camera initialization. Reproduce using the samples project on a Surface Go 2 or 3 and compare the reported MediaCapture exception. Done means taking a photo no longer crashes the Windows app.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100