Why does "new MediaCapture()" occasionally throws System.BadImageFormatException?

Hong 1,121 Reputation points
2021-01-24T08:20:18.15+00:00
 _mediaCapture = new MediaCapture();

The above statement of a UWP occasionally throws the following exception:

System.BadImageFormatException: Invalid access to memory location. (Exception from HRESULT: 0x800703E6)
Stack Trace: at System.Runtime.InteropServices.ExternalInterop.RoGetActivationFactory(String, Guid&, IntPtr&) + 0x197
at System.Runtime.InteropServices.FactoryCache.GetActivationFactoryInternal(String, RuntimeTypeHandle, ContextEntry) + 0x4a
at System.Runtime.InteropServices.FactoryCache.GetActivationFactory(String, RuntimeTypeHandle, Boolean) + 0x6c
at System.Runtime.InteropServices.McgMarshal.GetActivationFactory(String, RuntimeTypeHandle) + 0x24
at System.Runtime.InteropServices.McgMarshal.ActivateInstance(String) + 0x36
at Windows.Media.Capture.MediaCapture..ctor() + 0x1c

It is very rare. The statement usually works flawlessly.

Could anyone shed some light on this? What are the possible causes?

Universal Windows Platform (UWP)
{count} votes