Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

[UWP][IL2CPP] Export fails when trying to preserve class in .winmd via link.xml

Discussion in 'Windows' started by MacroPinch, Oct 25, 2018.

  1. MacroPinch

    MacroPinch

    Joined:
    Dec 6, 2013
    Posts:
    43
    Hi, here's the long story:
    Using Unity 2018.2.13f building UWP IL2CPP and using Vungle SDK 6.2.0 with our own wrapper (not the unity plugin).
    So, we are putting VungleSDK.winmd in Assets/Plugins/WSA
    Note that Strip Engine Code is Enabled.

    The export goes fine. Then building in VS and deploying to a device is also fine.
    During runtime, when trying to initialize the VungleSDK the diagnostic callback of the sdk throws the following error:

    Unobserved Task Exception was a Publisher Exception, type: VungleSDK.VungleAd, ex: System.Runtime.Serialization.InvalidDataContractException: No set method for property 'UseGzip' in type 'VungleSDK.NetworkRequest'.

    I'm guessing the striping process stripped the UseGzip method of VungleSDK.NetworkRequest (which is a protected class of the VungleSDK)

    So... we tried adding the following in link.xml

    <linker>
    <assembly fullname="VungleSDK">
    <type fullname="VungleSDK.NetworkRequest" preserve="all"/>
    </assembly>
    </linker>

    Unfortunately, after doing this the export process started crashing with the following exception:

    Failed running C:\dev\tools\unity\Editor\Data\il2cpp/build/UnityLinker.exe -out="C:\dev\projects\train\unity\Temp\StagingArea\Data\Managed\tempStrip" -x="C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\Core.xml" -x "C:\Users\Baceto\AppData\Local\Temp\tmpa654603.tmp" -x "C:\Users\Baceto\AppData\Local\Temp\tmp1ea6a612.tmp" -x "C:\Users\Baceto\AppData\Local\Temp\tmp385298bb.tmp" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\Accessibility.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\AI.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\Animation.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\AR.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\AssetBundle.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\Audio.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\Cloth.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\Core.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\CrashReporting.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\Director.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\GameCenter.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\Grid.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\ImageConversion.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\IMGUI.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\Input.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\JSONSerialize.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\Localization.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\ParticlesLegacy.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\ParticleSystem.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\PerformanceReporting.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\Physics.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\Physics2D.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\ScreenCapture.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\SharedInternals.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\SpriteMask.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\SpriteShape.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\Streaming.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\StyleSheets.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\Substance.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\Terrain.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\TerrainPhysics.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\TextRendering.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\Tilemap.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\UI.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\UIElements.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\UNET.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\UnityAnalytics.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\UnityConnect.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\UnityWebRequest.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\UnityWebRequestAssetBundle.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\UnityWebRequestAudio.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\UnityWebRequestTexture.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\UnityWebRequestWWW.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\Vehicles.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\Video.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\VR.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\Wind.xml" -x "C:\dev\tools\unity\Editor\Data\PlaybackEngines\MetroSupport\Whitelists\XR.xml" -x "C:\dev\projects\train\unity\Assets\link.xml" -d "C:\dev\projects\train\unity\Temp\StagingArea\Data\Managed" -a "C:\dev\projects\train\unity\Temp\StagingArea\Data\Managed\Assembly-CSharp-firstpass.dll" -a "C:\dev\projects\train\unity\Temp\StagingArea\Data\Managed\Assembly-CSharp.dll" -a "C:\dev\projects\train\unity\Temp\StagingArea\Data\Managed\Unity.TextMeshPro.dll" -a "C:\dev\projects\train\unity\Temp\StagingArea\Data\Managed\UnityEngine.UI.dll" -a "C:\dev\projects\train\unity\Temp\StagingArea\Data\Managed\DOTween.dll" -a "C:\dev\projects\train\unity\Temp\StagingArea\Data\Managed\NativeComm.dll" -a "C:\dev\projects\train\unity\Temp\StagingArea\Data\Managed\NestedPrefabs.dll" -a "C:\dev\projects\train\unity\Temp\StagingArea\Data\Managed\UnityEngine.Analytics.dll" -a "C:\dev\projects\train\unity\Temp\StagingArea\Data\Managed\I18N.CJK.dll" -a "C:\dev\projects\train\unity\Temp\StagingArea\Data\Managed\I18N.dll" -a "C:\dev\projects\train\unity\Temp\StagingArea\Data\Managed\I18N.MidEast.dll" -a "C:\dev\projects\train\unity\Temp\StagingArea\Data\Managed\I18N.Other.dll" -a "C:\dev\projects\train\unity\Temp\StagingArea\Data\Managed\I18N.Rare.dll" -a "C:\dev\projects\train\unity\Temp\StagingArea\Data\Managed\I18N.West.dll" --dotnetruntime=il2cpp --dotnetprofile=unityaot --use-editor-options

    stdout:
    Fatal error in Unity CIL Linker
    Mono.Linker.LoadException: Error while processing references of 'Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' ---> Mono.Linker.LoadException: Error while processing references of 'GCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' ---> Mono.Linker.LoadException: Error while processing references of 'NativeComm, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' ---> System.NullReferenceException: Object reference not set to an instance of an object.
    at Unity.IL2CPP.Common.WindowsRuntimeAwareMetadataResolver.FindTypeInUnknownWinmd(TypeReference type)
    at Mono.Cecil.TypeReference.Resolve()
    at Unity.IL2CPP.Common.AssemblyDependenciesComponent.ResolveWindowsRuntimeReferences(AssemblyDefinition assembly)
    at Unity.IL2CPP.Common.AssemblyDependenciesComponent.CollectAssemblyDependencies(AssemblyDefinition assembly)
    at Unity.IL2CPP.Common.AssemblyDependenciesComponent.GetReferencedAssembliesFor(AssemblyDefinition assembly)
    at Unity.Linker.UnityLinkContext.ResolveReferences(AssemblyDefinition assembly)
    at Mono.Linker.Steps.LoadReferencesStep.ProcessReferences(AssemblyDefinition assembly)
    at Mono.Linker.Steps.LoadReferencesStep.ProcessReferences(AssemblyDefinition assembly)
    --- End of inner exception stack trace ---
    at Mono.Linker.Steps.LoadReferencesStep.ProcessReferences(AssemblyDefinition assembly)
    at Mono.Linker.Steps.LoadReferencesStep.ProcessReferences(AssemblyDefinition assembly)
    --- End of inner exception stack trace ---
    at Mono.Linker.Steps.LoadReferencesStep.ProcessReferences(AssemblyDefinition assembly)
    at Mono.Linker.Steps.LoadReferencesStep.ProcessReferences(AssemblyDefinition assembly)
    --- End of inner exception stack trace ---
    at Mono.Linker.Steps.LoadReferencesStep.ProcessReferences(AssemblyDefinition assembly)
    at Mono.Linker.Steps.BaseStep.Process(LinkContext context)
    at Mono.Linker.Pipeline.Process(LinkContext context)
    at Unity.Linker.UnityDriver.Run()
    at Unity.Linker.UnityDriver.RunDriverWithoutErrorHandling()
    at Unity.Linker.UnityDriver.RunDriver()
    stderr:

    UnityEngine.Debug:LogError(Object)
    UnityEditorInternal.Runner:RunProgram(Program, String, String, String, CompilerOutputParserBase) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildUtils.cs:128)
    UnityEditorInternal.Runner:RunManagedProgram(String, String, String, CompilerOutputParserBase, Action`1) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildUtils.cs:73)
    UnityEditorInternal.AssemblyStripper:RunAssemblyLinker(IEnumerable`1, String&, String&, String, String) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/AssemblyStripper.cs:91)
    UnityEditorInternal.AssemblyStripper:StripAssembliesTo(String[], String[], String, String, String&, String&, String, IIl2CppPlatformProvider, IEnumerable`1, BuildTargetGroup) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/AssemblyStripper.cs:84)
    UnityEditorInternal.AssemblyStripper:RunAssemblyStripper(IEnumerable, String, String[], String[], String, IIl2CppPlatformProvider, RuntimeClassRegistry) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/AssemblyStripper.cs:215)
    UnityEditorInternal.AssemblyStripper:StripAssemblies(String, IIl2CppPlatformProvider, RuntimeClassRegistry) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/AssemblyStripper.cs:115)
    UnityEditorInternal.IL2CPPBuilder:Run() (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:170)
    UnityEditorInternal.IL2CPPUtils:RunIl2Cpp(String, String, IIl2CppPlatformProvider, Action`1, RuntimeClassRegistry) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:35)
    PostProcessUAPIl2Cpp:RunIL2CPP() (at C:/buildslave/unity/build/PlatformDependent/MetroPlayer/Extensions/Managed/PostProcessUAPIl2Cpp.cs:464)
    PostProcessWinRT:process() (at C:/buildslave/unity/build/PlatformDependent/MetroPlayer/Extensions/Managed/PostProcessWinRT.cs:228)
    UnityEditor.DefaultBuildMethods:BuildPlayer(BuildPlayerOptions)
    UnityEditorHelper.BundleManager:<startup>b__5_0(BuildPlayerOptions)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)
     
  2. MacroPinch

    MacroPinch

    Joined:
    Dec 6, 2013
    Posts:
    43
    Seems like the missing 'UseGzip' method is not stripped. It looks like Vungle has a problem with the config deserialization. The data contains reference to a missing property.

    Anyway, I think the NullReferenceException in the Unity CIL Linker shouldn't happen under any circumstance
     
  3. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,504
    Can we get a bug about NullReferenceException?

    As for preserving stuff in .winmd files, you need "windowsruntime" tag on the assembly:

    Code (csharp):
    1. <linker>
    2.    <assembly fullname="Windows" windowsruntime="true" ignoreIfMissing="1">
    3.        <type fullname="Windows.Foundation.Collections.IIterator`1" preserve="all" /> <!-- Used by IIteratorToIEnumeratorAdapter`1 -->
    4.        <type fullname="Windows.Foundation.Collections.IKeyValuePair`2" preserve="all" />  <!-- Used by runtime callable wrapper unboxing code at runtime -->
    5.        <type fullname="Windows.Foundation.IPropertyValue" preserve="all" /> <!-- Used by value type boxing to windows runtime -->
    6.        <type fullname="Windows.Foundation.IReference`1" preserve="all" />  <!-- Used by value type boxing to windows runtime -->
    7.        <type fullname="Windows.Foundation.IStringable" preserve="all" /> <!-- Used by Il2CppComObject.ToString() -->
    8.        <type fullname="Windows.UI.Xaml.Interop.IBindableIterator" preserve="all" /> <!-- Used by IBindableIteratorToIEnumeratorAdapter -->
    9.    </assembly>
    10. </linker>
     
  4. MacroPinch

    MacroPinch

    Joined:
    Dec 6, 2013
    Posts:
    43
    Thanks for the linker info. Submitted report for the null reference.
    Case 1094644
     
  5. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,504
    Thanks, we've got the bug report. Did you manage to workaround the exception by putting "windowsruntime" tag in the xml file?