ApplicationView.GetForCurrentView() occasionally throws "The service is already registered"

Hong 1,211 Reputation points
2021-05-19T14:49:49.557+00:00
ApplicationView avCurrent = ApplicationView.GetForCurrentView();

The above code occasionally throws the following exception:

System.Exception: The service is already registered.

The service is already registered.

Stack Trace:
at System.Runtime.InteropServices.McgMarshal.ThrowOnExternalCallFailed(Int32, RuntimeTypeHandle) + 0x21
at __Interop.ComCallHelpers.Call(__ComObject, RuntimeTypeHandle, Int32, Void*) + 0xbe
at __Interop.ForwardComStubs.Stub_3TThis, TResult + 0x37
at Windows.UI.ViewManagement.ApplicationView.GetForCurrentView() + 0x2c

It is rare. I am curious about the possible cause.

Universal Windows Platform (UWP)
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.