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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Can not build my scence in Unity when using Opc.Ua.Core.dll.

Discussion in 'Scripting' started by SyngnathZ, May 5, 2022.

  1. SyngnathZ

    SyngnathZ

    Joined:
    Jul 23, 2019
    Posts:
    5
    I built a relatively simple robot in Unity, and I referenced the UA .NetStandard library in it, which includes some dll files in the Assets/Plugins. When I tried to run it inside the Unity Editor, there is no problem with the scripts in it, the OPC UA server works fine, and the publish subscription works fine too. But when I want to compile them into an executable .exe file independently, Unity pops up some errors:


    Building Library\Bee\artifacts\WinPlayerBuildProgram\ManagedStripped failed with output:
    C:\Program Files\Unity 2021.2.16f1\Editor\Data\il2cpp\build\deploy\UnityLinker.exe --search-directory=C:/Users/MyComputer/UnityProjects/MyProject/Temp/StagingArea/Data/Managed --out=Library/Bee/artifacts/WinPlayerBuildProgram/ManagedStripped --include-link-xml=C:/Users/MyComputer/UnityProjects/MyProject/Temp/StagingArea/Data/Managed\MethodsToPreserve.xml --include-link-xml=C:/Users/MyComputer/UnityProjects/MyProject/Temp/StagingArea/Data/Managed\TypesInScenes.xml --include-link-xml=C:/Users/MyComputer/UnityProjects/MyProject/Temp/StagingArea/Data/Managed\SerializedTypes.xml --include-link-xml=C:\Users\MyComputer\UnityProjects\MyProject\Temp\burst.link.xml --include-directory=C:/Users/MyComputer/UnityProjects/MyProject/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 2021.2.16f1/Editor/Data/PlaybackEngines/WindowsStandaloneSupport/modules.asset --editor-data-file=C:/Users/MyComputer/UnityProjects/MyProject/Temp/StagingArea/Data/Managed/EditorToUnityLinkerData.json --include-unity-root-assembly=C:/Users/MyComputer/UnityProjects/MyProject/Temp/StagingArea/Data/Managed/Assembly-CSharp.dll --include-unity-root-assembly=C:/Users/MyComputer/UnityProjects/MyProject/Temp/StagingArea/Data/Managed/Unity.ML-Agents.dll --include-unity-root-assembly=C:/Users/MyComputer/UnityProjects/MyProject/Temp/StagingArea/Data/Managed/game4automation.interfaces.sharedmemory.dll --include-unity-root-assembly=C:/Users/MyComputer/UnityProjects/MyProject/Temp/StagingArea/Data/Managed/Unity.RenderPipelines.Universal.Runtime.dll --include-unity-root-assembly=C:/Users/MyComputer/UnityProjects/MyProject/Temp/StagingArea/Data/Managed/game4automation.spacenavigator.dll --include-unity-root-assembly=C:/Users/MyComputer/UnityProjects/MyProject/Temp/StagingArea/Data/Managed/Unity.RenderPipelines.Core.Runtime.dll --include-unity-root-assembly=C:/Users/MyComputer/UnityProjects/MyProject/Temp/StagingArea/Data/Managed/UnityEngine.UI.dll --include-unity-root-assembly=C:/Users/MyComputer/UnityProjects/MyProject/Temp/StagingArea/Data/Managed/game4automation.parts4cad.dll --include-unity-root-assembly=C:/Users/MyComputer/UnityProjects/MyProject/Temp/StagingArea/Data/Managed/game4automation.interfaces.s7tcpip.dll --include-unity-root-assembly=C:/Users/MyComputer/UnityProjects/MyProject/Temp/StagingArea/Data/Managed/game4automation.base.dll --include-unity-root-assembly=C:/Users/MyComputer/UnityProjects/MyProject/Temp/StagingArea/Data/Managed/NaughtyAttributes.Core.dll --include-unity-root-assembly=C:/Users/MyComputer/UnityProjects/MyProject/Temp/StagingArea/Data/Managed/I18N.dll --include-unity-root-assembly=C:/Users/MyComputer/UnityProjects/MyProject/Temp/StagingArea/Data/Managed/I18N.West.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 'Opc.Ua.Server, Version=1.4.368.0, Culture=neutral, PublicKeyToken=bfa7a73c5cf4b6e8' reference
    ---> Mono.Linker.LinkerFatalErrorException: ILLink: error IL1010: Assembly 'Opc.Ua.Server, Version=1.4.368.0, Culture=neutral, PublicKeyToken=bfa7a73c5cf4b6e8' cannot be loaded due to failure in processing 'Opc.Ua.Core, Version=1.4.368.0, Culture=neutral, PublicKeyToken=bfa7a73c5cf4b6e8' reference
    ---> Mono.Linker.LinkerFatalErrorException: ILLink: error IL1010: Assembly 'Opc.Ua.Core, Version=1.4.368.0, Culture=neutral, PublicKeyToken=bfa7a73c5cf4b6e8' cannot be loaded due to failure in processing 'Opc.Ua.Security.Certificates, Version=1.4.368.0, Culture=neutral, PublicKeyToken=bfa7a73c5cf4b6e8' 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.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.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()
    UnityEditor.GenericMenu:CatchMenu (object,string[],int)

    BuildFailedException: Incremental Player build failed!
    UnityEditor.Modules.BeeBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args) (at <ed149e892fca4713a3001773d054b5ca>:0)
    UnityEditor.Modules.DefaultBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at <ed149e892fca4713a3001773d054b5ca>:0)
    UnityEditor.WindowsStandalone.WinPlayerPostProcessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at C:/buildslave/unity/build/PlatformDependent/WinPlayer/Extensions/Managed/WinPlayerPostProcessor.cs:38)
    UnityEditor.PostprocessBuildPlayer.Postprocess (UnityEditor.BuildTargetGroup targetGroup, UnityEditor.BuildTarget target, System.Int32 subtarget, 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 <ed149e892fca4713a3001773d054b5ca>:0)
    UnityEditor.GenericMenu:CatchMenu(Object, String[], Int32)


    And I tried to add the link.xml as below:

    <linker>
    <assembly fullname="System" preserve="all"/>
    <assembly fullname="Mono.Options" preserve="all"/>
    <assembly fullname="Opc.Ua.Core" preserve="all"/>
    <assembly fullname="Opc.Ua.Client" preserve="all"/>
    <assembly fullname="Opc.Ua.PubSub" preserve="all"/>
    <assembly fullname="Opc.Ua.Server" preserve="all"/>
    <assembly fullname="Opc.Ua.Configuration" preserve="all"/>
    <assembly fullname="Opc.Ua.Security.Certificates" preserve="all"/>

    <assembly fullname="System.Core">
    <type fullname="System.Linq.Expressions.Interpreter.LightLambda" preserve="all" />
    </assembly>
    </linker>


    I'm using IL2CPP to be my backend, and using the .Net Standard 2.1.

    I wonder if anyone has tried a similar job and can suggest ideas to solve this problem, I would be very grateful !
     
  2. mike-voorhees

    mike-voorhees

    Unity Technologies

    Joined:
    Aug 9, 2016
    Posts:
    45
    My first guess would be that one or more of the precompiled assemblies in Asserts/Plugins has a reference to assembly that does not exist. You could try opening the assemblies in a tool such as ILSpy and verify the references make sense and all of those files exist.

    It looks like there are a number of other assemblies that are needed. A quick look at these assemblies and I see dependencies such as

    Newtonsoft.Json
    BouncyCastle.Crypto
    System.Formats.Asn1
     
  3. SyngnathZ

    SyngnathZ

    Joined:
    Jul 23, 2019
    Posts:
    5
    So all I have to do is find these dependencies and put them in the Asserts/Plugins and see if the compilation results are different? Let me try that ! Thanks!

    Also, I found that BouncyCastle.Crypto does not have a .Net Standard version, It only contains the .Net Framwork 4.0 version.
     
  4. SyngnathZ

    SyngnathZ

    Joined:
    Jul 23, 2019
    Posts:
    5
    After adding Newtonsoft.Json (BouncyCastle.Crypto and System.Formats.Asn1 I've added before), the error messages have changed as below:

    Building Library\Bee\artifacts\WinPlayerBuildProgram\ManagedStripped failed with output:
    C:\Program Files\Unity 2021.2.16f1\Editor\Data\il2cpp\build\deploy\UnityLinker.exe --search-directory=C:/Users/MyComputer/UnityProjects/MyProject/Temp/StagingArea/Data/Managed --out=Library/Bee/artifacts/WinPlayerBuildProgram/ManagedStripped --include-link-xml=C:/Users/MyComputer/UnityProjects/MyProject/Temp/StagingArea/Data/Managed\MethodsToPreserve.xml --include-link-xml=C:/Users/MyComputer/UnityProjects/MyProject/Temp/StagingArea/Data/Managed\TypesInScenes.xml --include-link-xml=C:/Users/MyComputer/UnityProjects/MyProject/Temp/StagingArea/Data/Managed\SerializedTypes.xml --include-link-xml=C:\Users\MyComputer\UnityProjects\MyProject\Temp\burst.link.xml --include-link-xml=C:\Users\MyComputer\UnityProjects\MyProject\Assets\link.xml --include-directory=C:/Users/MyComputer/UnityProjects/MyProject/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 2021.2.16f1/Editor/Data/PlaybackEngines/WindowsStandaloneSupport/modules.asset --editor-data-file=C:/Users/MyComputer/UnityProjects/MyProject/Temp/StagingArea/Data/Managed/EditorToUnityLinkerData.json --include-unity-root-assembly=C:/Users/MyComputer/UnityProjects/MyProject/Temp/StagingArea/Data/Managed/Assembly-CSharp.dll --include-unity-root-assembly=C:/Users/MyComputer/UnityProjects/MyProject/Temp/StagingArea/Data/Managed/Unity.ML-Agents.dll --include-unity-root-assembly=C:/Users/MyComputer/UnityProjects/MyProject/Temp/StagingArea/Data/Managed/game4automation.interfaces.sharedmemory.dll --include-unity-root-assembly=C:/Users/MyComputer/UnityProjects/MyProject/Temp/StagingArea/Data/Managed/Unity.RenderPipelines.Universal.Runtime.dll --include-unity-root-assembly=C:/Users/MyComputer/UnityProjects/MyProject/Temp/StagingArea/Data/Managed/game4automation.spacenavigator.dll --include-unity-root-assembly=C:/Users/MyComputer/UnityProjects/MyProject/Temp/StagingArea/Data/Managed/Unity.RenderPipelines.Core.Runtime.dll --include-unity-root-assembly=C:/Users/MyComputer/UnityProjects/MyProject/Temp/StagingArea/Data/Managed/UnityEngine.UI.dll --include-unity-root-assembly=C:/Users/MyComputer/UnityProjects/MyProject/Temp/StagingArea/Data/Managed/game4automation.parts4cad.dll --include-unity-root-assembly=C:/Users/MyComputer/UnityProjects/MyProject/Temp/StagingArea/Data/Managed/game4automation.interfaces.s7tcpip.dll --include-unity-root-assembly=C:/Users/MyComputer/UnityProjects/MyProject/Temp/StagingArea/Data/Managed/game4automation.base.dll --include-unity-root-assembly=C:/Users/MyComputer/UnityProjects/MyProject/Temp/StagingArea/Data/Managed/NaughtyAttributes.Core.dll --include-unity-root-assembly=C:/Users/MyComputer/UnityProjects/MyProject/Temp/StagingArea/Data/Managed/I18N.dll --include-unity-root-assembly=C:/Users/MyComputer/UnityProjects/MyProject/Temp/StagingArea/Data/Managed/I18N.West.dll --print-command-line
    Fatal error in Unity CIL Linker
    Mono.Linker.LinkerFatalErrorException: ILLink: error IL1010: Assembly 'Opc.Ua.Core, Version=1.4.368.0, Culture=neutral, PublicKeyToken=bfa7a73c5cf4b6e8' cannot be loaded due to failure in processing 'Opc.Ua.Security.Certificates, Version=1.4.368.0, Culture=neutral, PublicKeyToken=bfa7a73c5cf4b6e8' 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()
    UnityEditor.GenericMenu:CatchMenu (object,string[],int)


    My guess is that BouncyCastle.Crypto does not have a .Net Standard version (I've mentioned before), is that any possible solution?
    upload_2022-5-10_14-52-57.png
     
  5. SyngnathZ

    SyngnathZ

    Joined:
    Jul 23, 2019
    Posts:
    5
    I've used the Portable.BouncyCastle, most of the problems mentioned before disappered. But It still have serveal errors:


    C:\Program Files\Unity 2021.2.16f1\Editor\Data\il2cpp\build\deploy\il2cpp.exe @Library\Bee\artifacts\rsp\13037339541851228997.rsp
    Error: IL2CPP error for method 'System.Void TDx.TDxInput.SensorClass::add_SensorInput(TDx.TDxInput._ISensorEvents_SensorInputEventHandler)' in assembly 'C:\Users\MyComputer\UnityProjects\MyProject\Library\Bee\artifacts\WinPlayerBuildProgram\ManagedStripped\TDx.TDxInput.dll'
    System.NullReferenceException: Object reference not set to an instance of an object.
    at Unity.IL2CPP.MethodWriter.WriteMethodBodyForProjectedInterfaceMethod(IGeneratedMethodCodeWriter writer, MethodReference method, MethodReference interfaceMethod, IRuntimeMetadataAccess metadataAccess)
    at Unity.IL2CPP.MethodWriter.WriteMethodBodyForDirectComOrWindowsRuntimeCall(MinimalContext context, MethodReference method, IGeneratedMethodCodeWriter writer, IRuntimeMetadataAccess metadataAccess)
    at Unity.IL2CPP.MethodWriter.WriteMethodBodyForMethodWithoutBody(IGeneratedMethodCodeWriter writer, MethodReference method, IRuntimeMetadataAccess metadataAccess)
    at Unity.IL2CPP.CodeWriters.CodeWriterExtensions.WriteMethodWithMetadataInitialization(IGeneratedMethodCodeWriter writer, String methodSignature, Action`2 writeMethodBody, String uniqueIdentifier, MethodReference methodRef, Boolean writingMethodBody)
    at Unity.IL2CPP.MethodWriter.WriteMethodDefinition(AssemblyWriteContext context, IGeneratedMethodCodeWriter writer, MethodReference method)
    at Unity.IL2CPP.SourceWriter.WriteTypesMethods(SourceWritingContext context, IGeneratedMethodCodeWriter writer, TypeWritingInformation& writingInformation, NPath filePath, Boolean writeMarshalingDefinitions)
    at Unity.IL2CPP.SourceWriters.SourceWriterBase`2.WriteItem(StreamWorkItemData`2 data)
    at Unity.IL2CPP.Contexts.Scheduling.Streams.FileLevelParallelStreamManager`3.WorkerWriteItemsToFile(WorkItemData`2 data)
    at Unity.IL2CPP.Contexts.Scheduling.PhaseWorkScheduler`1.WorkerLoop(Object data)
    UnityEditor.GenericMenu:CatchMenu (object,string[],int)
     
  6. SyngnathZ

    SyngnathZ

    Joined:
    Jul 23, 2019
    Posts:
    5
    I discovered that the issue is in this DLL file (TDx.TDxInput.dll). Have you encountered any issues with IL2CPP errors after using this DLL? If you can tell me how to fix it, I would be very grateful!