UnityEngine.WSA.Application.windowActivated event not called when compiled using IL2CPP

I was able to get this event before while using the NetCore backend in Unity 2018, but now that I’m forced to use IL2CPP in Unity 2019, this event no longer seems to be triggered. The C++ generated code for the event registration and handling is there, but I never get the event.

public class HoloLensExternalDataInput : MonoBehaviour
{
    // Use this for initialization
    void Start ()
    {
        Debug.Log("HoloLensExternalDataInput-Start");
        UnityEngine.WSA.Application.windowActivated += Application_windowActivated;
    }

    private void Application_windowActivated(UnityEngine.WSA.WindowActivationState state)
    {
        var arguments = UnityEngine.WSA.Application.arguments;
        Debug.Log("Application_windowActivated - arguments: " + arguments);
    }
}

I see the Log statement for the Start method, but never the Log statement for the actual event.

I do see the built in log statements when running the app in debug mode:
[32.297251 / 41.280151] - OnWindowActivated event - Deactivated.
[1.585198 / 42.865348] - OnVisibilityChanged event - Hidden.
‘JTViewer.exe’ (Win32): Loaded ‘C:\Windows\System32\msxml6.dll’. Cannot find or open the PDB file.
[18.973996 / 61.839344] - OnHolographicWindowActivated event - CodeActivated.
[0.322481 / 62.161825] - OnVisibilityChanged event - Visible.
[0.020812 / 62.182637] - OnHolographicWindowActivated event - Deactivated.
[0.007574 / 62.190210] - OnWindowActivated event - CodeActivated.

This is a bug in our code :(. Could you file a bug report?

In the mean time, you can work around it by creating a file named “link.xml” with this content:

<linker>
       <assembly fullname="UnityEngine.CoreModule">
               <type fullname="UnityEngine.WSA.Application" preserve="nothing">
                      <method name="InvokeWindowActivatedEvent"/>
               </type>
       </assembly>
</linker>

And then putting it inside any folder in your project.

Thanks for the workaround. I have submitted a bug report

What’s the bug number?

Here is the issue tracker link for this bug: Unity Issue Tracker - [UWP] [IL2CPP] UnityEngine.WSA.Application.windowActivated is removed by IL2CPP Managed bytecode stripping