CommunityToolkit / CommunityToolkit/Maui
[BUG] CameraView System.InvalidOperationException: Unable to retrieve Handler
- 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
When I have a CameraView and start a Preview so a Picture can be captured the System.InvalidOperationException: Unable to retrieve Handler is raised.
Occurs on both iOS and Android.
`{System.InvalidOperationException: Unable to retrieve Handler at CommunityToolkit.Maui.Views.CameraView.get_Handler() in /_/src/CommunityToolkit.Maui.Camera/Views/CameraView.shared.cs:line 195 at CommunityToolkit.Maui.Views.CameraView.StartCameraPreview(CancellationToken token) in /_/src/CommunityToolkit.Maui.Camera/Views/CameraView.shared.cs:line 255 at MauiAppCameraView.Pages.CameraViewPage.OnAppearing() in D:\repo\MauiAppCameraView\MauiAppCameraView\Pages\CameraViewPage.xaml.cs:line 18 at System.Threading.Tasks.Task.<>c.b__128_0(Object state) at Foundation.NSAsyncSynchronizationContextDispatcher.Apply() in /Users/builder/azdo/_work/2/s/macios/src/Foundation/NSAction.cs:line 179 at Foundation.NSAsyncSynchronizationContextDispatcher.__Registrar_Callbacks__.callback_3681_Foundation_NSAsyncSynchronizationContextDispatcher_Apply(IntPtr pobj, IntPtr sel, IntPtr* exception_gchandle)}`
### Expected Behavior
CameaView works as documented. start a Preview and then capture an image.
### Steps To Reproduce
1. Open and debug simple app from repo at [https://github.com/Chris-Marassovich/MauiAppCameraView](url)
2. From the Shell Menu choose the "Camera" menu option and you should see the exception.
### Link to public reproduction project repository
https://github.com/Chris-Marassovich/MauiAppCameraView
### Environment
```markdown
"CommunityToolkit.Maui.Camera" Version="3.0.2"
"Microsoft.Maui.Controls" Version="9.0.120"
"CommunityToolkit.Mvvm" Version="8.4.0"
"CommunityToolkit.Maui" Version="12.2.0"
.NET workload is at
dotnet workload --info
Workload version: 9.0.302
Configured to use workload sets when installing new manifests.
Android is using an emulator Pixel 4 Android 12.0 API 31
iOS iPhone 13 Pro iOs 17.7
```
### Anything else?
Temporary workaround
Falling back to MediaPicker.CapturePhotoAsync() resolves the issue, but this is not suitable for us as I need to default the flash to off. This is a critical point for us and the only way I can programmatically default the flash to off is to use the CameraView.
If I can use the MediaPicker and still be able to default the flash to off that would be extremely helpful.
Contributor guide
Assessment
This issue has not been assessed yet.