Share via

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

Hong 1,526 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.

Developer technologies | Universal Windows Platform (UWP)

Your answer

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