Search Unity

Bug IL2CPP fails to compile because of the addressables

Discussion in 'Addressables' started by sebas77, Mar 2, 2021.

  1. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,642
    I get this error:

    Code (CSharp):
    1. Exception: Failed running C:\Program Files\Unity\Hub\Editor\2020.2.6f1\Editor\Data\il2cpp\build/deploy/netcoreapp3.1/UnityLinker.exe @C:/Prgdir/Gamecraft/GC_Mainline/Temp/StagingArea/Data/Managed/response.rsp
    2. stdout:
    3. Fatal error in Unity CIL Linker
    4. Mono.Linker.Steps.XmlResolutionException: Failed to process XML description: C:\Prgdir\Gamecraft\GC_Mainline\Assets\StreamingAssets\aa\AddressablesLink\link.xml
    5. ---> System.ArgumentException: Name can not be empty
    6.    at Mono.Cecil.AssemblyNameReference.Parse(String fullName)
    7.    at Mono.Linker.Steps.ResolveFromXmlStep.GetAssemblyName(XPathNavigator nav)
    8.    at Unity.Linker.Steps.Resolution.UnityResolveFromXmlStep.GetAssemblyName(XPathNavigator nav)
    9.    at Unity.Linker.Steps.Resolution.UnityResolveFromXmlStep.ProcessAssemblies(LinkContext context, XPathNodeIterator iterator)
    10.    at Mono.Linker.Steps.ResolveFromXmlStep.Process()
    11.    --- End of inner exception stack trace ---
    12.    at Mono.Linker.Steps.ResolveFromXmlStep.Process()
    13.    at Mono.Linker.Steps.BaseStep.Process(LinkContext context)
    14.    at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)
    15.    at Unity.Linker.UnityPipeline.ProcessStep(LinkContext context, IStep step)
    16.    at Mono.Linker.Pipeline.Process(LinkContext context)
    17.    at Unity.Linker.UnityDriver.UnityRun(ILogger customLogger)
    18.    at Unity.Linker.UnityDriver.RunDriverWithoutErrorHandling(ILogger customLogger)
    19.    at Unity.Linker.UnityDriver.RunDriver()
    20. stderr:
    21. UnityEditorInternal.Runner.RunProgram (UnityEditor.Utils.Program p, System.String exe, System.String args, System.String workingDirectory, UnityEditor.Scripting.Compilers.CompilerOutputParserBase parser) (at <8c48e4bc2ff34638b69095cbb65e2e27>:0)
    22. UnityEditorInternal.Runner.RunNetCoreProgram (System.String exe, System.String args, System.String workingDirectory, UnityEditor.Scripting.Compilers.CompilerOutputParserBase parser, System.Action`1[T] setupStartInfo) (at <8c48e4bc2ff34638b69095cbb65e2e27>:0)
    23. UnityEditorInternal.AssemblyStripper.RunAssemblyLinker (System.Collections.Generic.IEnumerable`1[T] args, System.String& out, System.String& err, System.String linkerPath, System.String workingDirectory) (at <8c48e4bc2ff34638b69095cbb65e2e27>:0)
    24. UnityEditorInternal.AssemblyStripper.StripAssembliesTo (System.String outputFolder, System.String& output, System.String& error, System.Collections.Generic.IEnumerable`1[T] linkXmlFiles, UnityEditorInternal.UnityLinkerRunInformation runInformation) (at <8c48e4bc2ff34638b69095cbb65e2e27>:0)
    25. UnityEditorInternal.AssemblyStripper.RunAssemblyStripper (UnityEditorInternal.UnityLinkerRunInformation runInformation) (at <8c48e4bc2ff34638b69095cbb65e2e27>:0)
    26. UnityEditorInternal.AssemblyStripper.StripAssemblies (System.String managedAssemblyFolderPath, UnityEditorInternal.BaseUnityLinkerPlatformProvider unityLinkerPlatformProvider, UnityEditorInternal.IIl2CppPlatformProvider il2cppPlatformProvider, UnityEditor.RuntimeClassRegistry rcr, UnityEditor.ManagedStrippingLevel managedStrippingLevel) (at <8c48e4bc2ff34638b69095cbb65e2e27>:0)
    27. UnityEditorInternal.IL2CPPBuilder.Run () (at <8c48e4bc2ff34638b69095cbb65e2e27>:0)
    28. UnityEditorInternal.IL2CPPUtils.RunIl2Cpp (System.String stagingAreaData, UnityEditorInternal.IIl2CppPlatformProvider platformProvider, System.Action`1[T] modifyOutputBeforeCompile, UnityEditor.RuntimeClassRegistry runtimeClassRegistry) (at <8c48e4bc2ff34638b69095cbb65e2e27>:0)
    29. DesktopStandalonePostProcessor.RunIL2CPP (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditorInternal.IIl2CppPlatformProvider il2cppPlatformProvider, System.Collections.Generic.List`1[T] cppPlugins) (at <8c48e4bc2ff34638b69095cbb65e2e27>:0)
    30. DesktopStandalonePostProcessor.SetupStagingArea (UnityEditor.Modules.BuildPostProcessArgs args, System.Collections.Generic.HashSet`1[T] filesToNotOverwrite) (at <8c48e4bc2ff34638b69095cbb65e2e27>:0)
    31. DesktopStandalonePostProcessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args) (at <8c48e4bc2ff34638b69095cbb65e2e27>:0)
    32. Rethrow as BuildFailedException: Exception of type 'UnityEditor.Build.BuildFailedException' was thrown.
    33. DesktopStandalonePostProcessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args) (at <8c48e4bc2ff34638b69095cbb65e2e27>:0)
    34. UnityEditor.Modules.DefaultBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at <8c48e4bc2ff34638b69095cbb65e2e27>:0)
    35. UnityEditor.PostprocessBuildPlayer.Postprocess (UnityEditor.BuildTargetGroup targetGroup, UnityEditor.BuildTarget target, System.String installPath, System.String companyName, System.String productName, System.Int32 width, System.Int32 height, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at <8c48e4bc2ff34638b69095cbb65e2e27>:0)
    36. UnityEditor.BuildPipeline:BuildPlayer(String[], String, BuildTarget, BuildOptions)
    37. GameBuild:BuildGame(BuildTarget, IEnumerable`1, DevMode, Boolean) (at Assets/Code/Editor/CompileOncePlease/GameBuild.cs:292)
    38. GameBuild:OnGUI() (at Assets/Code/Editor/CompileOncePlease/GameBuild.cs:145)
    39. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
    I have been told that somehow is related to this bug:

    https://issuetracker.unity3d.com/is...-with-custom-metadata-in-a-string-table-entry

    but I have updated the addressable package to that version and the problem persists.

    If this is a problem introduced by recent versions of the package, I can absolutely downgrade as I keep the package up to date, but without any strong reason.
     
  2. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,311
    1.17.6 is still failing with this issue on Unity 2020.2.6
    Issue does not occur on Unity 2020.1.14

    Code (CSharp):
    1. Exception: Failed running /Applications/Unity/Hub/Editor/2020.2.6f1/Unity.app/Contents/il2cpp/build/deploy/netcoreapp3.1/UnityLinker @"/Users/chrisfoulston/MyProject/Temp/StagingArea/Data/Managed/response.rsp"
    2. stdout:
    3. Fatal error in Unity CIL Linker
    4. Mono.Linker.Steps.XmlResolutionException: Failed to process XML description: /Users/chrisfoulston/MyProject/Assets/StreamingAssets/aa/AddressablesLink/link.xml
    5. ---> System.ArgumentException: Name can not be empty
    6.    at Mono.Cecil.AssemblyNameReference.Parse(String fullName)
    7.    at Mono.Linker.Steps.ResolveFromXmlStep.GetAssemblyName(XPathNavigator nav) in /Users/bokken/build/output/unity/il2cpp/repos/monolinker/src/linker/Linker.Steps/ResolveFromXmlStep.cs:line 660
    8.    at Unity.Linker.Steps.Resolution.UnityResolveFromXmlStep.GetAssemblyName(XPathNavigator nav) in /Users/bokken/build/output/unity/il2cpp/UnityLinker/Linker.Steps/Resolution/UnityResolveFromXmlStep.cs:line 171
    9.    at Unity.Linker.Steps.Resolution.UnityResolveFromXmlStep.ProcessAssemblies(LinkContext context, XPathNodeIterator iterator) in /Users/bokken/build/output/unity/il2cpp/UnityLinker/Linker.Steps/Resolution/UnityResolveFromXmlStep.cs:line 77
    10.    at Mono.Linker.Steps.ResolveFromXmlStep.Process() in /Users/bokken/build/output/unity/il2cpp/repos/monolinker/src/linker/Linker.Steps/ResolveFromXmlStep.cs:line 93
    11.    --- End of inner exception stack trace ---
    12.    at Mono.Linker.Steps.ResolveFromXmlStep.Process() in /Users/bokken/build/output/unity/il2cpp/repos/monolinker/src/linker/Linker.Steps/ResolveFromXmlStep.cs:line 96
    13.    at Mono.Linker.Steps.BaseStep.Process(LinkContext context) in /Users/bokken/build/output/unity/il2cpp/repos/monolinker/src/linker/Linker.Steps/BaseStep.cs:line 60
    14.    at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step) in /Users/bokken/build/output/unity/il2cpp/repos/monolinker/src/linker/Linker/Pipeline.cs:line 135
    15.    at Unity.Linker.UnityPipeline.ProcessStep(LinkContext context, IStep step) in /Users/bokken/build/output/unity/il2cpp/UnityLinker/Linker/UnityPipeline.cs:line 23
    16.    at Mono.Linker.Pipeline.Process(LinkContext context) in /Users/bokken/build/output/unity/il2cpp/repos/monolinker/src/linker/Linker/Pipeline.cs:line 127
    17.    at Unity.Linker.UnityDriver.UnityRun(ILogger customLogger) in /Users/bokken/build/output/unity/il2cpp/UnityLinker/Linker/UnityDriver.cs:line 98
    18.    at Unity.Linker.UnityDriver.RunDriverWithoutErrorHandling(ILogger customLogger) in /Users/bokken/build/output/unity/il2cpp/UnityLinker/Linker/UnityDriver.cs:line 66
    19.    at Unity.Linker.UnityDriver.RunDriver() in /Users/bokken/build/output/unity/il2cpp/UnityLinker/Linker/UnityDriver.cs:line 48
    20. stderr:
    21. UnityEditorInternal.Runner.RunProgram (UnityEditor.Utils.Program p, System.String exe, System.String args, System.String workingDirectory, UnityEditor.Scripting.Compilers.CompilerOutputParserBase parser) (at /Users/bokken/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildUtils.cs:133)
    22. UnityEditorInternal.Runner.RunNetCoreProgram (System.String exe, System.String args, System.String workingDirectory, UnityEditor.Scripting.Compilers.CompilerOutputParserBase parser, System.Action`1[T] setupStartInfo) (at /Users/bokken/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildUtils.cs:91)
    23. UnityEditorInternal.AssemblyStripper.RunAssemblyLinker (System.Collections.Generic.IEnumerable`1[T] args, System.String& out, System.String& err, System.String linkerPath, System.String workingDirectory) (at /Users/bokken/buildslave/unity/build/Editor/Mono/BuildPipeline/AssemblyStripper.cs:155)
    24. UnityEditorInternal.AssemblyStripper.StripAssembliesTo (System.String outputFolder, System.String& output, System.String& error, System.Collections.Generic.IEnumerable`1[T] linkXmlFiles, UnityEditorInternal.UnityLinkerRunInformation runInformation) (at /Users/bokken/buildslave/unity/build/Editor/Mono/BuildPipeline/AssemblyStripper.cs:146)
    25. UnityEditorInternal.AssemblyStripper.RunAssemblyStripper (UnityEditorInternal.UnityLinkerRunInformation runInformation) (at /Users/bokken/buildslave/unity/build/Editor/Mono/BuildPipeline/AssemblyStripper.cs:261)
    26. UnityEditorInternal.AssemblyStripper.StripAssemblies (System.String managedAssemblyFolderPath, UnityEditorInternal.BaseUnityLinkerPlatformProvider unityLinkerPlatformProvider, UnityEditorInternal.IIl2CppPlatformProvider il2cppPlatformProvider, UnityEditor.RuntimeClassRegistry rcr, UnityEditor.ManagedStrippingLevel managedStrippingLevel) (at /Users/bokken/buildslave/unity/build/Editor/Mono/BuildPipeline/AssemblyStripper.cs:167)
    27. UnityEditorInternal.IL2CPPBuilder.Run () (at /Users/bokken/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:581)
    28. UnityEditorInternal.IL2CPPUtils.RunIl2Cpp (System.String tempFolder, System.String stagingAreaData, UnityEditorInternal.IIl2CppPlatformProvider platformProvider, System.Action`1[T] modifyOutputBeforeCompile, UnityEditor.RuntimeClassRegistry runtimeClassRegistry) (at /Users/bokken/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:269)
    29. UnityEditor.iOS.PostProcessiPhonePlayer.CrossCompileManagedDlls (UnityEditor.iOS.PostProcessiPhonePlayer+BuildSettings bs, UnityEditor.iOS.PostProcessiPhonePlayer+ProjectPaths paths, UnityEditor.AssemblyReferenceChecker checker, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport buildReport) (at /Users/bokken/buildslave/unity/build/PlatformDependent/iPhonePlayer/Extensions/Common/BuildPostProcessor.cs:908)
    30. UnityEditor.iOS.PostProcessiPhonePlayer.PostProcess (UnityEditor.iOS.PostProcessiPhonePlayer+BuildSettings bs, UnityEditor.iOS.PostProcessiPhonePlayer+ProjectPaths paths, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport buildReport) (at /Users/bokken/buildslave/unity/build/PlatformDependent/iPhonePlayer/Extensions/Common/BuildPostProcessor.cs:718)
    31. UnityEditor.iOS.PostProcessiPhonePlayer.PostProcess (UnityEditor.iOS.PostProcessorSettings postProcessorSettings, UnityEditor.Modules.BuildPostProcessArgs args) (at /Users/bokken/buildslave/unity/build/PlatformDependent/iPhonePlayer/Extensions/Common/BuildPostProcessor.cs:663)
    32. UnityEditor.iOS.iOSBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args) (at /Users/bokken/buildslave/unity/build/PlatformDependent/iPhonePlayer/Extensions/Common/ExtensionModule.cs:45)
    33. Rethrow as BuildFailedException: Exception of type 'UnityEditor.Build.BuildFailedException' was thrown.
    34. UnityEditor.iOS.iOSBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args) (at /Users/bokken/buildslave/unity/build/PlatformDependent/iPhonePlayer/Extensions/Common/ExtensionModule.cs:49)
    35. UnityEditor.Modules.DefaultBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at /Users/bokken/buildslave/unity/build/Editor/Mono/Modules/DefaultBuildPostprocessor.cs:29)
    36. UnityEditor.PostprocessBuildPlayer.Postprocess (UnityEditor.BuildTargetGroup targetGroup, UnityEditor.BuildTarget target, System.String installPath, System.String companyName, System.String productName, System.Int32 width, System.Int32 height, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at /Users/bokken/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:337)
    37. UnityEditor.DefaultBuildMethods:BuildPlayer(BuildPlayerOptions)
     
    Last edited: Mar 3, 2021
  3. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,642
    yes we discussed this and the fix is actually not published yet.
     
  4. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,642
    as a workaround the only thing you can do is to make the addressable and the scriptable build pipeline local packages and change the following file found in the SBP to this:

    Code (CSharp):
    1. using System;
    2. using System.Collections.Generic;
    3. using System.Reflection;
    4. using System.Xml;
    5. using System.IO;
    6. using System.Linq;
    7. using System.Text;
    8. namespace UnityEditor.Build.Pipeline.Utilities
    9. {
    10.     /// <summary>
    11.     /// This can be used to create a LinkXml for your build.  This will ensure that the desired runtime types are packed into the build.
    12.     /// </summary>
    13.     public class LinkXmlGenerator
    14.     {
    15.         Dictionary<Type, Type> m_TypeConversion = new Dictionary<Type, Type>();
    16.         HashSet<Type> m_Types = new HashSet<Type>();
    17.         HashSet<Assembly> m_Assemblies = new HashSet<Assembly>();
    18.         /// <summary>
    19.         /// Obsolete, no longer does anything.
    20.         /// </summary>
    21.         [Obsolete] protected Dictionary<string, HashSet<string>> serializedClassesPerAssembly = null;
    22.         Dictionary<string, HashSet<string>> m_SerializedClassesPerAssembly = new Dictionary<string, HashSet<string>>();
    23.         /// <summary>
    24.         /// Constructs and returns a LinkXmlGenerator object that contains default UnityEditor to UnityEngine type conversions.
    25.         /// </summary>
    26.         /// <returns>LinkXmlGenerator object with the default UnityEngine type conversions.</returns>
    27.         public static LinkXmlGenerator CreateDefault()
    28.         {
    29.             var linker = new LinkXmlGenerator();
    30.             var types = GetEditorTypeConversions();
    31.             foreach (var pair in types)
    32.                 linker.SetTypeConversion(pair.Key, pair.Value);
    33.             return linker;
    34.         }
    35.         /// <summary>
    36.         /// Returns the set of UnityEditor types that have valid runtime direct mappings.
    37.         /// </summary>
    38.         /// <returns>Array of KeyValuePairs containing the editor type and it's equivalent runtime type.</returns>
    39.         public static KeyValuePair<Type, Type>[] GetEditorTypeConversions()
    40.         {
    41.             var editor = Assembly.GetAssembly(typeof(UnityEditor.BuildPipeline));
    42.             return new[]
    43.             {
    44.                 new KeyValuePair<Type, Type>(typeof(UnityEditor.Animations.AnimatorController), typeof(UnityEngine.RuntimeAnimatorController)),
    45.                 new KeyValuePair<Type, Type>(editor.GetType("UnityEditor.Audio.AudioMixerController"), typeof(UnityEngine.Audio.AudioMixer)),
    46.                 new KeyValuePair<Type, Type>(editor.GetType("UnityEditor.Audio.AudioMixerGroupController"), typeof(UnityEngine.Audio.AudioMixerGroup)),
    47.             };
    48.         }
    49.         /// <summary>
    50.         /// Add runtime assembly to the LinkXml Generator.
    51.         /// </summary>
    52.         /// <param name="assemblies">The desired runtime assemblies.</param>
    53.         public void AddAssemblies(params Assembly[] assemblies)
    54.         {
    55.             if (assemblies == null)
    56.                 return;
    57.             foreach (var a in assemblies)
    58.                 AddAssemblyInternal(a);
    59.         }
    60.         /// <summary>
    61.         /// Add runtime assembly to the LinkXml Generator.
    62.         /// </summary>
    63.         /// <param name="assemblies">The desired runtime assemblies.</param>
    64.         public void AddAssemblies(IEnumerable<Assembly> assemblies)
    65.         {
    66.             if (assemblies == null)
    67.                 return;
    68.             foreach (var a in assemblies)
    69.                 AddAssemblyInternal(a);
    70.         }
    71.         /// <summary>
    72.         /// Add runtime type to the LinkXml Generator.
    73.         /// </summary>
    74.         /// <param name="types">The desired runtime types.</param>
    75.         public void AddTypes(params Type[] types)
    76.         {
    77.             if (types == null)
    78.                 return;
    79.             foreach (var t in types)
    80.                 AddTypeInternal(t);
    81.         }
    82.         /// <summary>
    83.         /// Add runtime type to the LinkXml Generator.
    84.         /// </summary>
    85.         /// <param name="types">The desired runtime types.</param>
    86.         public void AddTypes(IEnumerable<Type> types)
    87.         {
    88.             if (types == null)
    89.                 return;
    90.             foreach (var t in types)
    91.                 AddTypeInternal(t);
    92.         }
    93.         /// <summary>
    94.         /// Add SerializedReference class type from fully qualified name to the Generator, those will end up in PreservedTypes.xml
    95.         /// </summary>
    96.         /// <param name="serializedRefTypes">The SerializeReference instance fully qualified name we want to preserve.</param>
    97.         public void AddSerializedClass(IEnumerable<string> serializedRefTypes)
    98.         {
    99.             if (serializedRefTypes == null)
    100.                 return;
    101.             foreach (var t in serializedRefTypes)
    102.             {
    103.                 var indexOfAssembly = t.IndexOf(':');
    104.                 if (indexOfAssembly != -1)
    105.                     AddSerializedClassInternal(t.Substring(0, indexOfAssembly), t.Substring(indexOfAssembly + 1, t.Length - (indexOfAssembly + 1)));
    106.             }
    107.         }
    108.         private void AddTypeInternal(Type t)
    109.         {
    110.             if (t == null)
    111.                 return;
    112.             Type convertedType;
    113.             if (m_TypeConversion.TryGetValue(t, out convertedType))
    114.                 m_Types.Add(convertedType);
    115.             else
    116.                 m_Types.Add(t);
    117.         }
    118.         private void AddSerializedClassInternal(string assemblyName, string classWithNameSpace)
    119.         {
    120.             if (string.IsNullOrEmpty(assemblyName))
    121.                 return;
    122.             if (string.IsNullOrEmpty(classWithNameSpace))
    123.                 return;
    124.             if (!m_SerializedClassesPerAssembly.TryGetValue(assemblyName, out HashSet<string> types))
    125.                 m_SerializedClassesPerAssembly[assemblyName] = types = new HashSet<string>();
    126.             types.Add(classWithNameSpace);
    127.         }
    128.         private void AddAssemblyInternal(Assembly a)
    129.         {
    130.             if (a == null)
    131.                 return;
    132.             m_Assemblies.Add(a);
    133.         }
    134.         /// <summary>
    135.         /// Setup runtime type conversion
    136.         /// </summary>
    137.         /// <param name="a">Convert from type.</param>
    138.         /// <param name="b">Convert to type.</param>
    139.         public void SetTypeConversion(Type a, Type b)
    140.         {
    141.             m_TypeConversion[a] = b;
    142.         }
    143.         /// <summary>
    144.         /// Save the LinkXml to the specified path.
    145.         /// </summary>
    146.         /// <param name="path">The path to save the linker xml file.</param>
    147.         public void Save(string path)
    148.         {
    149.             var assemblyMap = new Dictionary<Assembly, List<Type>>();
    150.             foreach (var a in m_Assemblies)
    151.             {
    152.                 if (!assemblyMap.TryGetValue(a, out _))
    153.                     assemblyMap.Add(a, new List<Type>());
    154.             }
    155.             foreach (var t in m_Types)
    156.             {
    157.                 var a = t.Assembly;
    158.                 List<Type> types;
    159.                 if (!assemblyMap.TryGetValue(a, out types))
    160.                     assemblyMap.Add(a, types = new List<Type>());
    161.                 types.Add(t);
    162.             }
    163.             XmlDocument doc = new XmlDocument();
    164.             var linker = doc.AppendChild(doc.CreateElement("linker"));
    165.             foreach (var k in assemblyMap)
    166.             {
    167.                 var assembly = linker.AppendChild(doc.CreateElement("assembly"));
    168.                 var attr = doc.CreateAttribute("fullname");
    169.                 attr.Value = k.Key.FullName;
    170.                 if (assembly.Attributes != null)
    171.                 {
    172.                     assembly.Attributes.Append(attr);
    173.                     if (m_Assemblies.Contains(k.Key))
    174.                     {
    175.                         var preserveAssembly = doc.CreateAttribute("preserve");
    176.                         preserveAssembly.Value = "all";
    177.                         assembly.Attributes.Append(preserveAssembly);
    178.                     }
    179.                     foreach (var t in k.Value)
    180.                     {
    181.                         var typeEl = assembly.AppendChild(doc.CreateElement("type"));
    182.                         var tattr = doc.CreateAttribute("fullname");
    183.                         tattr.Value = t.FullName;
    184.                         if (typeEl.Attributes != null)
    185.                         {
    186.                             typeEl.Attributes.Append(tattr);
    187.                             var pattr = doc.CreateAttribute("preserve");
    188.                             pattr.Value = "all";
    189.                             typeEl.Attributes.Append(pattr);
    190.                         }
    191.                     }
    192.                     //Add serialize reference classes which are contained in the current assembly
    193.                     var assemblyName = k.Key.GetName().Name;
    194.                     if (m_SerializedClassesPerAssembly.ContainsKey(assemblyName))
    195.                     {
    196.                         //Add content for this
    197.                         foreach (var t in m_SerializedClassesPerAssembly[assemblyName])
    198.                         {
    199.                             var typeEl = assembly.AppendChild(doc.CreateElement("type"));
    200.                             var tattr = doc.CreateAttribute("fullname");
    201.                             tattr.Value = t;
    202.                             if (typeEl.Attributes != null)
    203.                             {
    204.                                 typeEl.Attributes.Append(tattr);
    205.                                 var pattr = doc.CreateAttribute("preserve");
    206.                                 pattr.Value = "nothing";
    207.                                 typeEl.Attributes.Append(pattr);
    208.                                 var sattr = doc.CreateAttribute("serialized");
    209.                                 sattr.Value = "true";
    210.                                 typeEl.Attributes.Append(sattr);
    211.                             }
    212.                         }
    213.                         m_SerializedClassesPerAssembly.Remove(assemblyName);
    214.                     }
    215.                 }
    216.             }
    217.             //Add serialize reference classes which are contained in other assemblies not yet removed.
    218.             foreach (var k in m_SerializedClassesPerAssembly)
    219.             {
    220.                 var assembly = linker.AppendChild(doc.CreateElement("assembly"));
    221.                 var attr = doc.CreateAttribute("fullname");
    222.                 attr.Value = k.Key;
    223.                 if (assembly.Attributes != null)
    224.                 {
    225.                     assembly.Attributes.Append(attr);
    226.                     //Add content for this
    227.                     foreach (var t in k.Value)
    228.                     {
    229.                         var typeEl = assembly.AppendChild(doc.CreateElement("type"));
    230.                         var tattr = doc.CreateAttribute("fullname");
    231.                         tattr.Value = t;
    232.                         if (typeEl.Attributes != null)
    233.                         {
    234.                             typeEl.Attributes.Append(tattr);
    235.                             var pattr = doc.CreateAttribute("preserve");
    236.                             pattr.Value = "nothing";
    237.                             typeEl.Attributes.Append(pattr);
    238.                             var sattr = doc.CreateAttribute("serialized");
    239.                             sattr.Value = "true";
    240.                             typeEl.Attributes.Append(sattr);
    241.                         }
    242.                     }
    243.                 }
    244.             }
    245.             doc.Save(path);
    246.         }
    247.     }
    248. }
    249.  
     
    CDF likes this.
  5. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,311
    Thanks. This also works for us:
    patching the link.xml after addressables build. So doesn't require making a local copy of the package

    Code (CSharp):
    1.  
    2. public static class BuildUtility {
    3.  
    4.     [InitializeOnLoadMethod]
    5.     private static void Initialize() {
    6.  
    7.         BuildScript.buildCompleted -= OnAddressableBuildComplete;
    8.         BuildScript.buildCompleted += OnAddressableBuildComplete;
    9.     }
    10.  
    11.     private static void OnAddressableBuildComplete(AddressableAssetBuildResult result) {
    12.  
    13.         Debug.Log($"Addressables Build Complete: {result.OutputPath}");
    14.  
    15.         PatchAddressablesLinkXML();
    16.     }
    17.  
    18.     private static void PatchAddressablesLinkXML() {
    19.  
    20.         string path = Addressables.BuildPath + "/AddressablesLink/link.xml";
    21.  
    22.         Debug.Log($"Patching Link XML: {path}");
    23.  
    24.         XmlDocument doc = new XmlDocument();
    25.         doc.Load(path);
    26.  
    27.         //remove assemblies that have no attributes
    28.  
    29.         var assemblies = doc.SelectNodes("/linker/assembly[count(@*)=0]");
    30.  
    31.         for (int i = 0; i < assemblies.Count; i++) {
    32.  
    33.             var node = assemblies[i];
    34.  
    35.             node.ParentNode.RemoveChild(node);
    36.         }
    37.  
    38.         doc.Save(path);
    39.  
    40.         AssetDatabase.Refresh();
    41.  
    42.         Debug.Log("Link XML Patched!");
    43.     }
    44. }
    45.  
     
    Last edited: Mar 4, 2021
    adamgolden and sebas77 like this.
  6. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,555
    Thanks @CDF, a recent update to 2021.2.0a13 and Addressables 1.17.17 caused a similar exception due to a UnityEditor assembly in the link.xml. Here's the fix, I took the same approach:
    Code (CSharp):
    1. private static void PatchAddressablesLinkXML()
    2. {
    3.   string path = Addressables.BuildPath + "/AddressablesLink/link.xml";
    4.   XmlDocument doc = new XmlDocument();
    5.   doc.Load(path);
    6.   var assemblies = doc.SelectNodes("/linker/assembly[@fullname='UnityEditor.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null']");
    7.   for (int i = 0; i < assemblies.Count; i++) assemblies[i].ParentNode.RemoveChild(assemblies[i]);
    8.   doc.Save(path);
    9. }