Exception when deploying to HL2 in Project migrated from XR SDK/OpenXR (Unity 2020.2) to Legacy XR (Unity 2019.4) ?
Describe the bug
The app works and runs as expected in the Unity Editor Player. Upon building it in VS2019 and then running it on the Hololens 2 however, I receive an error and exception (see screenshot). The app then does not start on the HL2, the content stays blank,
I'm using the "Windows Mixed Reality" (deprecated) Package and "Legacy XR Input Helpers" Package in Unity 2019.4.20f1 in order to enable gesture support. This hasn't been implemented for OpenXR or the new XR SDK yet (#9492 #7271). The project was created in Unity 2020.2 and migrated to 2019.4.
For the Build in Unity I turned on Copy References, PDB files, Development Build and Deep Profiling Support .
It seems like the exception has something to do with WindowsMRXRSDK.dll?
Expected behavior
App should build and run successfully with working Gesture support on the HL2.
Screenshots

Your setup (please complete the following information)
- Unity 2019.4.20f1
- MRTK 2.6.1
Target platform (please complete the following information)
- HoloLens 2
This looks like the result of a bug where Windows XR Plugin isn't cleaning up its build settings after the build.
As a workaround, you can drop the following code into your project. It'll create a new menu item at the top labeled "TEMP", which will contain an option to clean up these build settings. You should see something like Before: vr-enabled:1;xrsdk-windowsmr-library:WindowsMRXRSDK;early-boot-windows-holographic:1;force-primary-window-holographic:1, After: in the console after running, indicating that it's been cleaned up. Subsequent builds should be successful. Feel free to delete this script after as well!
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System.Collections.Generic;
using UnityEditor;
public class CleanUpBuildConfig
{
private const string XrBootSettingsKey = "xr-boot-settings";
private const string ForcePrimaryWindowHolographic = "force-primary-window-holographic";
private const string VrEnabled = "vr-enabled";
private const string WmrLibrary = "xrsdk-windowsmr-library";
private const string EarlyBootHolographic = "early-boot-windows-holographic";
private static readonly Dictionary<string, string> BootConfigSettings = new Dictionary<string, string>();
#if UNITY_EDITOR
[MenuItem("TEMP/Clean up build config")]
private static void CleanUp()
{
string buildTargetName = BuildPipeline.GetBuildTargetName(BuildTarget.WSAPlayer);
string xrBootSettings = EditorUserBuildSettings.GetPlatformSettings(buildTargetName, XrBootSettingsKey);
if (!string.IsNullOrEmpty(xrBootSettings))
{
string[] bootSettings = xrBootSettings.Split(';');
foreach (var bootSetting in bootSettings)
{
var setting = bootSetting.Split(':');
if (setting.Length == 2 && !string.IsNullOrEmpty(setting[0]) && !string.IsNullOrEmpty(setting[1]))
{
BootConfigSettings.Add(setting[0], setting[1]);
}
}
}
UnityEngine.Debug.Log($"Before: {xrBootSettings}");
if (BootConfigSettings.ContainsKey(ForcePrimaryWindowHolographic))
{
BootConfigSettings.Remove(ForcePrimaryWindowHolographic);
}
if (BootConfigSettings.ContainsKey(VrEnabled))
{
BootConfigSettings.Remove(VrEnabled);
}
if (BootConfigSettings.ContainsKey(WmrLibrary))
{
BootConfigSettings.Remove(WmrLibrary);
}
if (BootConfigSettings.ContainsKey(EarlyBootHolographic))
{
BootConfigSettings.Remove(EarlyBootHolographic);
}
bool firstEntry = true;
var sb = new System.Text.StringBuilder();
foreach (KeyValuePair<string, string> kvp in BootConfigSettings)
{
if (!firstEntry)
{
sb.Append(";");
}
sb.Append($"{kvp.Key}:{kvp.Value}");
firstEntry = false;
}
UnityEngine.Debug.Log($"After: {sb}");
EditorUserBuildSettings.SetPlatformSettings(buildTargetName, XrBootSettingsKey, sb.ToString());
}
#endif // UNITY_EDITOR
}
Looks like the bug fix on the Windows XR Plugin side shipped in the latest versions across Unity 2019 (2.8.0), 2020 (4.5.0), and 2021 (5.3.0), so I'm going to close this tracking issue out.