Search Unity

UWP IL2CPP build fails if .winmd plugin references System.Xml due to an exception in il2cpp.exe

Discussion in 'Windows' started by Yuriy-Ivanov, Jun 4, 2018.

  1. Yuriy-Ivanov

    Yuriy-Ivanov

    Joined:
    Jun 12, 2015
    Posts:
    495
    Dear Unity support team and community,

    I'm a developer of a popular asset UTNotifications. Currently the asset doesn't support IL2CPP builds for UWP/Windows Store. Our customers requested this feature, so I tried enabling non-dummy UWP implementation when
    ENABLE_WINMD_SUPPORT is defined, not only when #if !IL2CPP. Unfortunately, it causes the build to fail with the following error:

    Code (csharp):
    1.  
    2. Failed running C:\Program Files\Unity\Editor\Data\il2cpp/build/il2cpp.exe --convert-to-cpp --emit-null-checks --enable-array-bounds-check --dotnetprofile="unityjit" --map-file-parser="C:\Program Files\Unity\Editor\Data\Tools\MapFileParser\MapFileParser.exe" --assembly="C:\Users\u-n-i\Documents\projects\utnotifications\unity\Temp\StagingArea\Data\Managed\Assembly-CSharp-firstpass.dll" --assembly="C:\Users\u-n-i\Documents\projects\utnotifications\unity\Temp\StagingArea\Data\Managed\Assembly-CSharp.dll" --assembly="C:\Users\u-n-i\Documents\projects\utnotifications\unity\Temp\StagingArea\Data\Managed\UnityEngine.UI.dll" --assembly="C:\Users\u-n-i\Documents\projects\utnotifications\unity\Temp\StagingArea\Data\Managed\I18N.CJK.dll" --assembly="C:\Users\u-n-i\Documents\projects\utnotifications\unity\Temp\StagingArea\Data\Managed\I18N.dll" --assembly="C:\Users\u-n-i\Documents\projects\utnotifications\unity\Temp\StagingArea\Data\Managed\I18N.MidEast.dll" --assembly="C:\Users\u-n-i\Documents\projects\utnotifications\unity\Temp\StagingArea\Data\Managed\I18N.Other.dll" --assembly="C:\Users\u-n-i\Documents\projects\utnotifications\unity\Temp\StagingArea\Data\Managed\I18N.Rare.dll" --assembly="C:\Users\u-n-i\Documents\projects\utnotifications\unity\Temp\StagingArea\Data\Managed\I18N.West.dll" --assembly="C:\Users\u-n-i\Documents\projects\utnotifications\unity\Temp\StagingArea\Data\Managed\UnityEngine.dll" --generatedcppdir="C:\Users\u-n-i\Documents\projects\utnotifications\unity\Temp\StagingArea\Il2CppOutputProject\Source\il2cppOutput"
    3. stdout:
    4. IL2CPP error for type 'System.Xml.Schema.SequenceNode/SequenceConstructPosContext' in assembly 'C:\Users\u-n-i\Documents\projects\utnotifications\unity\Temp\StagingArea\Data\Managed\System.Xml.dll'
    5. Additional information: Build a development build for more information. Value cannot be null.
    6. Parameter name: key
    7. il2cpp.exe didn't catch exception: System.ArgumentNullException: Value cannot be null.
    8. Parameter name: key
    9.   at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
    10.   at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
    11.   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
    12.   at Unity.IL2CPP.Metadata.MetadataCollector.GetTypeInfoIndex(TypeDefinition type)
    13.   at Unity.IL2CPP.Il2CppTypeWriter.WriteIl2CppTypeDefinitions(IMetadataCollection metadataCollection)
    14.   at Unity.IL2CPP.MetadataCacheWriter.WriteLibIl2CppMetadata(NPath outputDir, NPath dataFolder, ICollection`1 usedAssemblies, MethodTables methodTables, IMetadataCollection metadataCollector, IAttributeCollection attributeCollection, VTableBuilder vTableBuilder, IMethodCollectorResults methodCollector, IInteropDataCollectorResults interopDataCollector, UnresolvedVirtualsTablesInfo virtualCallTables, IInvokerCollection invokerCollection, SourceWritingContext sourceWritingContext, IMetadataUsageCollectorReaderService metadataUsages, IIl2CppMethodReferenceCollectorWriterService methodReferenceCollector)
    15.   at Unity.IL2CPP.AssemblyConverter.Apply()
    16.   at Unity.IL2CPP.AssemblyConverter.ConvertAssemblies(IEnumerable`1 assemblyDirectories, IEnumerable`1 explicitAssemblies, NPath outputDir, NPath dataFolder, NPath symbolsFolder, NPath executableAssembiesFolder, NPath monoLibFolder, NPath monoEtcFolder, NPath[] searchDirectories, String entryAssemblyName, NPath[] extraTypesFiles)
    17.   at il2cpp.Program.DoRun(String[] args)
    18.   at il2cpp.Program.Run(String[] args)
    19.   at il2cpp.Program.Main(String[] args)
    20. stderr:
    21. Unhandled Exception: System.ArgumentNullException: Value cannot be null.
    22. Parameter name: key
    23.   at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
    24.   at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
    25.   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
    26.   at Unity.IL2CPP.Metadata.MetadataCollector.GetTypeInfoIndex(TypeDefinition type)
    27.   at Unity.IL2CPP.Il2CppTypeWriter.WriteIl2CppTypeDefinitions(IMetadataCollection metadataCollection)
    28.   at Unity.IL2CPP.MetadataCacheWriter.WriteLibIl2CppMetadata(NPath outputDir, NPath dataFolder, ICollection`1 usedAssemblies, MethodTables methodTables, IMetadataCollection metadataCollector, IAttributeCollection attributeCollection, VTableBuilder vTableBuilder, IMethodCollectorResults methodCollector, IInteropDataCollectorResults interopDataCollector, UnresolvedVirtualsTablesInfo virtualCallTables, IInvokerCollection invokerCollection, SourceWritingContext sourceWritingContext, IMetadataUsageCollectorReaderService metadataUsages, IIl2CppMethodReferenceCollectorWriterService methodReferenceCollector)
    29.   at Unity.IL2CPP.AssemblyConverter.Apply()
    30.   at Unity.IL2CPP.AssemblyConverter.ConvertAssemblies(IEnumerable`1 assemblyDirectories, IEnumerable`1 explicitAssemblies, NPath outputDir, NPath dataFolder, NPath symbolsFolder, NPath executableAssembiesFolder, NPath monoLibFolder, NPath monoEtcFolder, NPath[] searchDirectories, String entryAssemblyName, NPath[] extraTypesFiles)
    31.   at il2cpp.Program.DoRun(String[] args)
    32.   at il2cpp.Program.Run(String[] args)
    33.   at il2cpp.Program.Main(String[] args)
    34. UnityEngine.Debug:LogError(Object)
    35. UnityEditorInternal.Runner:RunProgram(Program, String, String, String, CompilerOutputParserBase) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildUtils.cs:128)
    36. UnityEditorInternal.Runner:RunManagedProgram(String, String, String, CompilerOutputParserBase, Action`1) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildUtils.cs:73)
    37. UnityEditorInternal.IL2CPPBuilder:RunIl2CppWithArguments(List`1, Action`1, String) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:362)
    38. UnityEditorInternal.IL2CPPBuilder:ConvertPlayerDlltoCpp(ICollection`1, String, String, Boolean) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:343)
    39. UnityEditorInternal.IL2CPPBuilder:Run() (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:162)
    40. UnityEditorInternal.IL2CPPUtils:RunIl2Cpp(String, String, IIl2CppPlatformProvider, Action`1, RuntimeClassRegistry) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:35)
    41. PostProcessUAPIl2Cpp:RunIL2CPP() (at C:/buildslave/unity/build/PlatformDependent/MetroPlayer/Extensions/Managed/PostProcessUAPIl2Cpp.cs:464)
    42. PostProcessWinRT:process() (at C:/buildslave/unity/build/PlatformDependent/MetroPlayer/Extensions/Managed/PostProcessWinRT.cs:231)
    43. UnityEngine.GUIUtility:processEvent(Int32, IntPtr)
    44.  
    45.  
    I.e. it fails to get type info for System.Xml.Schema.SequenceNode/SequenceConstructPosContext (in System.Xml). Unfortunately, `Windows.Data.Xml` is required for configuring notifications in Windows Store/UWP, and it depends on System.Xml.

    Is there any workaround for that issue? Or is it going to be fixed in new updates of il2cpp?

    It's Unity 2018.1.1, host OS: Windows 10, target OS: UWP, .Net 3.5 or 4, scripting backend: IL2CPP.

    Thanks for any help,
    Best regards,
    Yuriy, Universal Tools team.
     
    Last edited: Jun 4, 2018
    Wadjey likes this.
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    Hey, can we get a bug report on this?
     
  3. Yuriy-Ivanov

    Yuriy-Ivanov

    Joined:
    Jun 12, 2015
    Posts:
    495
    I've just submitted a bug report with the same title as this forum topic title.
    Looking forward to hearing anything.
     
  4. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    Thanks, we will take a look.
     
  5. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    Hi! So, good news. I've looked at this bug report and it seems like I have already fixed it as part of another bug report that we received just 1 day before yours. I'll be backporting this change all the way back to 2018.1.

    Furthermore, there is a workaround you can do on your side to work around this if you want the fix sooner: instead of compiling your code into a windows runtime component (.winmd), compile it into a class library (.dll):
    upload_2018-6-12_13-12-28.png

    IL2CPP had some issues processing .winmd files that were compiled from C# code, rather than C++.
     
    Yuriy-Ivanov likes this.
  6. Yuriy-Ivanov

    Yuriy-Ivanov

    Joined:
    Jun 12, 2015
    Posts:
    495
    Great, thank you!
    Unfortunately .dll is not an option: background tasks which we use to handle received WNS notifications and other functionality, require being contained in .winmd library (Windows/Windows Phone even copies that library on registering a background task into its own internal location so it can be invoked whenever required without starting the parent app).
    So I'll be waiting for the update and enable the WSA implementation #if ENABLE_WINMD_SUPPORT then.
     
  7. zolg

    zolg

    Joined:
    Aug 9, 2013
    Posts:
    33
    Hi. Any news about this problem? I came across this issue related to Vungle's Unity SDK (https://dashboard.vungle.com/sdk). That package also uses a .winmd plugin for UWP builds instead of a .dll and it fails to build when the IL2CPP backend is selected.

    I tested this on Windows 10 for the following Unity version:

    Unity 2018.1.0f1
    Unity 2018.2.11f1
    Unity 2018.3.0b4

    Build platform: UWP, .Net 4, IL2CPP scripting backend.

    Thanks!
     
  8. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    @zolg the .winmd issue was fixed a while ago - in fact, it is fixed in both 2018.2.11f1 and 2018.3.0b4. For 2018.1, it was fixed in 2018.1.8f1.

    Are you sure you're facing the same issue?
     
  9. zolg

    zolg

    Joined:
    Aug 9, 2013
    Posts:
    33
    Sorry, you are right. I tested again, and the plugin builds fine in Unity 2018.2.11f1 and 2018.3.0b4. I experienced the issue only in Unity 2018.1.0f1 but as you mentioned the fix was applied in Unity 2018.1.8f1, so a simple project upgrade should work for me.

    Thanks for the info!
     
  10. RichmarIII

    RichmarIII

    Joined:
    Mar 15, 2015
    Posts:
    7
    I'm having the same issue with 2019.3.11f. anytime i add a winmd library, it fails to build with the exact same error as you. "value cannot be null"
     
  11. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    Can you file a bug report on that? What kind of winmd file are you adding?