doghappy / socket.io-client-csharp

socket.io-client implemention for .NET
MIT License
729 stars 125 forks source link

Unity IL2CPP build issues #267

Closed Snowblaze closed 2 years ago

Snowblaze commented 2 years ago

After building the Newtonsoft project on newtonsoft branch, I imported both dlls (socketio, newtonsoft.json) into Unity. Was getting build error regarding newtonsoft.json package:

Building Library\Bee\artifacts\WinPlayerBuildProgram\ManagedStripped failed with output:
C:\Program Files\Unity\Hub\Editor\2021.2.11f1\Editor\Data\il2cpp\build\deploy\UnityLinker.exe --search-directory=D:/Snowblaze Entertainment/simple-fps/Temp/StagingArea/Data/Managed --out=Library/Bee/artifacts/WinPlayerBuildProgram/ManagedStripped --include-link-xml=D:/Snowblaze Entertainment/simple-fps/Temp/StagingArea/Data/Managed\TypesInScenes.xml --include-link-xml=D:/Snowblaze Entertainment/simple-fps/Temp/StagingArea/Data/Managed\SerializedTypes.xml --include-link-xml=D:/Snowblaze Entertainment/simple-fps/Assets\..\Temp\InputSystemLink.xml --include-link-xml=D:\Snowblaze Entertainment\simple-fps\Temp\burst.link.xml --include-directory=D:/Snowblaze Entertainment/simple-fps/Temp/StagingArea/Data/Managed --dotnetprofile=unityaot-win32 --dotnetruntime=Il2Cpp --platform=WindowsDesktop --use-editor-options --editor-settings-flag=None,Development --engine-modules-asset-file=C:/Program Files/Unity/Hub/Editor/2021.2.11f1/Editor/Data/PlaybackEngines/WindowsStandaloneSupport/modules.asset --editor-data-file=D:/Snowblaze Entertainment/simple-fps/Temp/StagingArea/Data/Managed/EditorToUnityLinkerData.json --include-unity-root-assembly=D:/Snowblaze Entertainment/simple-fps/Temp/StagingArea/Data/Managed/Assembly-CSharp.dll --include-unity-root-assembly=D:/Snowblaze Entertainment/simple-fps/Temp/StagingArea/Data/Managed/Unity.RenderPipelines.Universal.Runtime.dll --include-unity-root-assembly=D:/Snowblaze Entertainment/simple-fps/Temp/StagingArea/Data/Managed/Unity.TextMeshPro.dll --include-unity-root-assembly=D:/Snowblaze Entertainment/simple-fps/Temp/StagingArea/Data/Managed/Unity.InputSystem.dll --include-unity-root-assembly=D:/Snowblaze Entertainment/simple-fps/Temp/StagingArea/Data/Managed/Unity.RenderPipelines.Core.Runtime.dll --include-unity-root-assembly=D:/Snowblaze Entertainment/simple-fps/Temp/StagingArea/Data/Managed/UnityEngine.UI.dll --include-unity-root-assembly=D:/Snowblaze Entertainment/simple-fps/Temp/StagingArea/Data/Managed/Cinemachine.dll --print-command-line
ILLink: error IL1999: ERROR: Failed to resolve base type Newtonsoft.Json.JsonConverter for type SocketIOClient.JsonSerializer.ByteArrayConverter in assembly SocketIOClient.dll when linking against the UnityAot-Win32 profile
Fatal error in Unity CIL Linker
Unity.Linker.StrippingResolutionBaseTypeException: ERROR: Failed to resolve base type Newtonsoft.Json.JsonConverter for type SocketIOClient.JsonSerializer.ByteArrayConverter in assembly SocketIOClient.dll when linking against the UnityAot-Win32 profile
   at Unity.Linker.MonoBehaviorUtilities.DerivesFrom(UnityLinkContext context, TypeDefinition type, String[] possibleBaseNames)
   at Unity.Linker.MonoBehaviorUtilities.IsMonoBehaviourOrScriptableObject(UnityLinkContext context, TypeDefinition type)
   at Unity.Linker.Steps.Rooting.ResolveFromMonoBehaviours.<Process>b__6_0(TypeDefinition t)
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at Unity.Linker.Steps.Rooting.ResolveFromMonoBehaviours.Process(LinkContext context)
   at Unity.Linker.UnityPipeline.ProcessStep(LinkContext context, IStep step)
   at Mono.Linker.Pipeline.Process(LinkContext context)
   at Unity.Linker.UnityDriver.UnityRun(Boolean noProfilerAllowed, ILogger customLogger)
   at Unity.Linker.UnityDriver.RunDriverWithoutErrorHandling(ILogger customLogger, Boolean noProfilerAllowed)
   at Unity.Linker.UnityDriver.RunDriver()
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

After renaming it to exactly Newtonsoft.Json now I'm getting this error on build for desktop:

Building Library\Bee\artifacts\WinPlayerBuildProgram\ManagedStripped failed with output:
C:\Program Files\Unity\Hub\Editor\2021.2.11f1\Editor\Data\il2cpp\build\deploy\UnityLinker.exe --search-directory=D:/Snowblaze Entertainment/simple-fps/Temp/StagingArea/Data/Managed --out=Library/Bee/artifacts/WinPlayerBuildProgram/ManagedStripped --include-link-xml=D:/Snowblaze Entertainment/simple-fps/Temp/StagingArea/Data/Managed\MethodsToPreserve.xml --include-link-xml=D:/Snowblaze Entertainment/simple-fps/Temp/StagingArea/Data/Managed\TypesInScenes.xml --include-link-xml=D:/Snowblaze Entertainment/simple-fps/Temp/StagingArea/Data/Managed\SerializedTypes.xml --include-link-xml=D:/Snowblaze Entertainment/simple-fps/Assets\..\Temp\InputSystemLink.xml --include-link-xml=D:\Snowblaze Entertainment\simple-fps\Temp\burst.link.xml --include-directory=D:/Snowblaze Entertainment/simple-fps/Temp/StagingArea/Data/Managed --dotnetprofile=unityaot-win32 --dotnetruntime=Il2Cpp --platform=WindowsDesktop --use-editor-options --editor-settings-flag=None,Development --engine-modules-asset-file=C:/Program Files/Unity/Hub/Editor/2021.2.11f1/Editor/Data/PlaybackEngines/WindowsStandaloneSupport/modules.asset --editor-data-file=D:/Snowblaze Entertainment/simple-fps/Temp/StagingArea/Data/Managed/EditorToUnityLinkerData.json --include-unity-root-assembly=D:/Snowblaze Entertainment/simple-fps/Temp/StagingArea/Data/Managed/Assembly-CSharp.dll --include-unity-root-assembly=D:/Snowblaze Entertainment/simple-fps/Temp/StagingArea/Data/Managed/Unity.RenderPipelines.Universal.Runtime.dll --include-unity-root-assembly=D:/Snowblaze Entertainment/simple-fps/Temp/StagingArea/Data/Managed/Unity.TextMeshPro.dll --include-unity-root-assembly=D:/Snowblaze Entertainment/simple-fps/Temp/StagingArea/Data/Managed/Unity.InputSystem.dll --include-unity-root-assembly=D:/Snowblaze Entertainment/simple-fps/Temp/StagingArea/Data/Managed/Unity.RenderPipelines.Core.Runtime.dll --include-unity-root-assembly=D:/Snowblaze Entertainment/simple-fps/Temp/StagingArea/Data/Managed/UnityEngine.UI.dll --include-unity-root-assembly=D:/Snowblaze Entertainment/simple-fps/Temp/StagingArea/Data/Managed/Cinemachine.dll --print-command-line
Fatal error in Unity CIL Linker
Mono.Linker.LinkerFatalErrorException: ILLink: error IL1010: Assembly 'Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' cannot be loaded due to failure in processing 'SocketIOClient, Version=3.0.5.0, Culture=neutral, PublicKeyToken=c9a3629195a82104' reference
 ---> System.NullReferenceException: Object reference not set to an instance of an object.
   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.ResolveFromXmlStep.GetAssembly(LinkContext context, AssemblyNameReference assemblyName)
   at Unity.Linker.Steps.Resolution.UnityResolveFromXmlStep.ProcessAssemblies(XPathNodeIterator iterator)
   at Mono.Linker.Steps.ProcessLinkerXmlStepBase.ProcessXml(Boolean stripResource, Boolean ignoreResource)
   at Mono.Linker.Steps.BaseStep.Process(LinkContext context)
   at Unity.Linker.UnityPipeline.ProcessStep(LinkContext context, IStep step)
   at Mono.Linker.Pipeline.Process(LinkContext context)
   at Unity.Linker.UnityDriver.UnityRun(Boolean noProfilerAllowed, ILogger customLogger)
   at Unity.Linker.UnityDriver.RunDriverWithoutErrorHandling(ILogger customLogger, Boolean noProfilerAllowed)
   at Unity.Linker.UnityDriver.RunDriver()
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

As far as I can tell Unity couln't get the referenced packages. Not sure what to do tbh

Snowblaze commented 2 years ago

After removing the newtonsoft.json dll imported from the solution, I installed jilleJr newtonsoft package and IL2CPP build was successful.