I am getting the following exception when I call CompositionCapabilities.GetForCurrentView
.
System.UnauthorizedAccessException: 'Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))'
public App()
{
this.InitializeComponent();
this.Suspending += OnSuspending;
// Exception happens here.
var capabilities = CompositionCapabilities.GetForCurrentView();
}
The weird thing is the code compiles OK so I assume the API is available. Do I need to declare any capabilities in Package.appxmanifest?
You don't need to declare anything. The method is simply called too early.
So instead of calling it in the constructor, call it right after the Window is created -
protected override void OnWindowCreated(WindowCreatedEventArgs args)
{
if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 4))
{
var capabilities = CompositionCapabilities.GetForCurrentView();
var areEffectsSupported = capabilities.AreEffectsSupported();
var areEffectsFast = capabilities.AreEffectsFast();
}
base.OnWindowCreated(args);
}
Note you will want to add a check to see if that API is supported too, like in the code above.