1

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?

Jessica
  • 2,057
  • 1
  • 15
  • 24
  • Tip: never call something, not even some of your own classes, immediately after the App.InitializeComponent()... it will fail quite certainly. – Luca Lindholm Jun 16 '17 at 10:10

1 Answers1

2

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.

Justin XL
  • 38,763
  • 7
  • 88
  • 133