3

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.

AwAw123
  • 33
  • 1
  • 4

2 Answers2

5

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

Martin Zikmund
  • 38,440
  • 7
  • 70
  • 91
  • I have updated my answer with a few more things to try – Martin Zikmund Jan 19 '18 at 22:37
  • I am on the latest version of Windows 10, last checked a few hours ago. Application uninstalled, computer restarted, code re-downloaded, created a new VS solution, recompiled and re-ran the application but still the same problem. – AwAw123 Jan 19 '18 at 22:46
  • That is very weird :-( ... Could you possibly post a sample project which causes this exception so that I could run it here and confirm if it happens universally? – Martin Zikmund Jan 19 '18 at 22:48
  • Download files in https://github.com/ms-iot/samples/tree/develop/WebcamApp/CS - It already has a sln file. Open it, compile as x64 or x86 and run on your Win 10 laptop / desktop with Webcam! Thanks buddy. – AwAw123 Jan 19 '18 at 22:50
  • Surprisingly it works on my PC :-O . Please try the newer version of the sample as well (https://github.com/Microsoft/Windows-iotcore-samples/tree/develop/Samples/WebcamApp), but even the one you linked worked after I gave the permission to access camera. – Martin Zikmund Jan 19 '18 at 23:14
  • 1
    Even the newer code did not work. But at least it's not universal. I will now have to look for some unusual setting on my computer to get it to work. – AwAw123 Jan 19 '18 at 23:40
  • @AwAw123 can you check you pc privacy settings maybe app not allow to access camera – Shubham Sahu Jan 20 '18 at 15:00
  • @ShubhamSahu The camera in pc privacy settings is on for all apps including the one that I am developing. Thank you for input. Any other ideas? – AwAw123 Jan 22 '18 at 02:56
  • @AwAw123 according to martin , you app working fine on his pc, so something in your pc which is blocking your app from accessing camera, so can you check your antivirus also because i have as an antivirus "AVG" which has feature to block accessing camera from app, so i will check your app sample in my pc later – Shubham Sahu Jan 22 '18 at 04:18
  • The code works on other machines. I know I will now have to do a clean install of the windows to make it work, but just don't want to do it now. Thank you for help everyone. – AwAw123 Jan 26 '18 at 01:08
  • I had the same issue but got it working in the end. In 'windows > settings > privacy settings' I had to enable general and app specific access to camera and microphone. Also my Bitdefender Firewall had a web cam protection and I needed to unblock it specifically for the app. – Florian May 23 '18 at 08:35
0

I was bothered by this issue for hours and later noticed it only happened in my debug build and not release build. It turned out there is a separate manifest file for debug, named Debug.appxmanifest, as opposed to the Package.appxmanifest used by Release build.

Rick Lee
  • 19
  • 1
  • 2