UWP CompositionRadialGradientBrush throws cast error on HoloLens

134 views Asked by At

After releasing a UWP application to the Windows Store that runs well on both desktop and Xbox, I noticed that it was not launching successfully when installed as a 2D application on a HoloLens.

Hooking it up to a debugger I discovered the following error:

System.InvalidCastException: 'Unable to cast object of type 'Windows.UI.Composition.Compositor' to type 'Windows.UI.Composition.ICompositorWithRadialGradient'.'

on the following line of code:

CompositionRadialGradientBrush RGBrush = compositor.CreateRadialGradientBrush();

Is there a known compatibility issue with the HoloLens not supporting the radial gradient brush functionality of Windows.UI.Composition?

Besides conditionally skipping this section of code that applies the gradient background when running on a HoloLens are there any other ways to get around this or to get the api to work correctly?

1

There are 1 answers

0
Nathan - MSFT On

HoloSheep,

To detect if running on HL1 or HL2, there is stack overflow post that details how to do that via application code. This is from post:

"the best way to do this is by using platform capabilities utility, since that will work as new devices come out, and across platforms. For example, instead of checking "am on on HoloLens 2" you can check "does my device support articulated hands?". That will then work on other platforms that support articulated hands. For an example, check out MixedRealityToolkit.Examples/Demos/Utilities/Scenes/MixedRealityCapabilityDemo.unity in MRTK examples.

If you need a temporary solution for now to differentiate WMR from HL1 from HL2, you can use the following code. Note it's windows-only:

using Windows.Security.ExchangeActiveSyncProvisioning;

EasClientDeviceInformation CurrentInfo = new EasClientDeviceInformation();
string sku = CurrentInfo.SystemSku;

HoloLens 1, HoloLens 2, and Immersive headsets should all return different strings.

It's also possible to check the runtime platform as follows:

if (Application.platform == RuntimePlatform.WSAPlayerARM)
{
     // Running HoloLens 2, most likely.
}

Original post link is here: How do you detect whether your Mixed Reality app is running on HoloLens 1, HoloLens 2 or an immersive headset?

Thanks! Nathan