Search code examples
c#permissionsuwpwin-universal-appwebcam

Access being denied to webcam in a UWP app


I was trying to create a simple UWP application to access my webcam following tutorial https://developer.microsoft.com/en-us/windows/iot/samples/webcamapp using code at https://github.com/ms-iot/samples/tree/develop/WebcamApp/CS on my Windows 10 laptop using VS 2017, 15.5.3. Both x64 and x86 builds give me the same access denied error i.e.

Exception thrown: 'System.UnauthorizedAccessException' in System.Private.CoreLib.ni.dll 
WinRT information: Access is denied.

on line 202 in MainPage.xaml.cs at await mediaCapture.InitializeAsync();

Before throwing the exception, the app does ask for the user permission to let it use the camera but even clicking yes does not make a difference.

My drivers for the camera are 100% up to date, and other UWP apps can access camera fine as was the case here. I have looked into other questions that talk about file IO access problems with UWP apps, but was unable to use them as a clue to solve the access to webcam.

Any help will be greatly appreciated. Thank you.


Solution

  • You have to set the Microphone and Webcam capabilities in the App Manifest.

    • In Solution Explorer, double-click the package.appxmanifest

    • Select the Capabilities tab.

    • Check the box for Webcam and the box for Microphone.

    Update

    Are you running a stable version of Windows 10? Please, try uninstalling the application from your device and then deleting the bin and obj folders from the project folder to make sure there are no leftovers. Finally, please try to open the app without the debugger (e.g. from the Start menu) if that doesn't change the result