Unity's HoloLens photo capture script is not working with error of "InvalidOperationException" and "Assertion failed: Failed to initialize IMediaCapture (hr = 0xC00DABE0)".

I am trying to capture a photo on my HoloLens app. I have used HoloLens photo capture script mentioned in Unity’s manual.
Link of Unity’s manual: Unity - Manual: XR architecture

First I got an error for InvalidOperationException which I have solved with the help of following thread :
c# - SupportedResolutions of Unitys PhotoCapture is empty - Stack Overflow.

I have changed my Start method in code as per below:

 void Start()
        // Create a PhotoCapture object
        PhotoCapture.CreateAsync(false, delegate (PhotoCapture captureObject) {

            Resolution cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First();
            targetTexture = new Texture2D(cameraResolution.width, cameraResolution.height);

            photoCaptureObject = captureObject;
            CameraParameters cameraParameters = new CameraParameters();
            cameraParameters.hologramOpacity = 0.0f;
            cameraParameters.cameraResolutionWidth = cameraResolution.width;
            cameraParameters.cameraResolutionHeight = cameraResolution.height;
            cameraParameters.pixelFormat = CapturePixelFormat.BGRA32;

            // Activate the camera
            photoCaptureObject.StartPhotoModeAsync(cameraParameters, delegate (PhotoCapture.PhotoCaptureResult result) {
                // Take a picture

Now, my script is resulting in a new error :

Assertion failed: Failed to initialize
IMediaCapture (hr = 0xC00DABE0)

I have used Mixed Reality Toolkit and attached this script on my main camera.
I have also specified the webcam and microphone capabilities from player settings in Unity and give permission to use the camera from my HoloLens to my app.

Can anybody help me with this?

I have not found any solution for this bug mention above. But by using this source code I succeed to capture a photo from my HoloLens app.
I hope this will help others in the same way.