I am working on a project where we need to integrate a CAN communication.
The customer is using a device from Peak. It has a NuGet .Net Standard 2.0 package [Peak.PCANBasic.NET]
Platform: Windows
The problem is that we can’t build with IL2CPP and Burst. Just Mono works. However, this is very constraining for us.
As soon as IL2CPP/Burst is included, we can no longer build. As it strips too much away?
>> The following error appears in the editor:
Failed to find entry-points:
System.Exception: Error while hashing assembly E:\Projects\PCANProject\Assets\Peak.PCANBasic.NET.4.8.0.830\lib\netstandard2.0\PCANBasic.NET.dll —> System.AggregateException: One or more errors occurred. (Error while hashing type reference ‘1000084’ in assembly ‘PCANBasic.NET.dll’) —> System.Exception: Error while hashing type reference ‘1000084’ in assembly ‘PCANBasic.NET.dll’ —> System.BadImageFormatException: Read out of bounds.
at System.Reflection.Throw.OutOfBounds () [0x00005] in :0
at System.Reflection.Internal.MemoryBlock.PeekHeapReference (System.Int32 offset, System.Boolean smallRefSize) [0x00003] in :0
at System.Reflection.Metadata.Ecma335.TypeRefTableReader.GetNamespace (System.Reflection.Metadata.TypeReferenceHandle handle) [0x00011] in :0
at System.Reflection.Metadata.TypeReference.get_Namespace () [0x00019] in :0
at Burst.Compiler.IL.Hashing.CacheBuilder.Util.SrmExtensions.WriteFullNameTo (System.Reflection.Metadata.TypeReference& typeReference, Burst.Compiler.IL.Helpers.Hash128Builder builder, Burst.Compiler.IL.Hashing.CacheBuilder.Util.CachingMetadataReader reader) [0x00000] in <772865cdae2d4bff9c305a06338cabcf>:0
at Burst.Compiler.IL.Hashing.CacheBuilder.Util.SrmExtensions.WriteFullNameTo (System.Reflection.Metadata.TypeReference& typeReference, Burst.Compiler.IL.Helpers.Hash128Builder builder, Burst.Compiler.IL.Hashing.CacheBuilder.Util.CachingMetadataReader reader) [0x00050] in <772865cdae2d4bff9c305a06338cabcf>:0
at Burst.Compiler.IL.Hashing.CacheBuilder.ILHasher.HashTypeReferenceImpl (System.Reflection.Metadata.TypeReferenceHandle typeReferenceHandle) [0x0007b] in <772865cdae2d4bff9c305a06338cabcf>:0
at Burst.Compiler.IL.Hashing.CacheBuilder.ILHasher.HashTypeReference (System.Reflection.Metadata.TypeReferenceHandle typeReferenceHandle) [0x00000] in <772865cdae2d4bff9c305a06338cabcf>:0
— End of inner exception stack trace —
at Burst.Compiler.IL.Hashing.CacheBuilder.ILHasher.HashTypeReference (System.Reflection.Metadata.TypeReferenceHandle typeReferenceHandle) [0x00031] in <772865cdae2d4bff9c305a06338cabcf>:0
at Burst.Compiler.IL.Hashing.CacheBuilder.ILHasher+<>c__DisplayClass14_0.b__6 (System.Reflection.Metadata.TypeReferenceHandle typeReferenceHandle, System.Threading.Tasks.ParallelLoopState loopState, System.Int64 i) [0x00000] in <772865cdae2d4bff9c305a06338cabcf>:0
at Burst.Compiler.IL.Hashing.CacheBuilder.ILHasher.ForEach[T] (System.Collections.Generic.IEnumerable1[T] elements, System.Action3[T1,T2,T3] callback) [0x00018] in <772865cdae2d4bff9c305a06338cabcf>:0
at Burst.Compiler.IL.Hashing.CacheBuilder.ILHasher+<>c__DisplayClass14_0.b__1 () [0x00000] in <772865cdae2d4bff9c305a06338cabcf>:0
at System.Threading.Tasks.Task.InnerInvoke () [0x0000f] in <787acc3c9a4c471ba7d971300105af24>:0
at System.Threading.Tasks.Task.Execute () [0x00000] in <787acc3c9a4c471ba7d971300105af24>:0
— End of inner exception stack trace —
at System.Threading.Tasks.Task.WaitAll (System.Threading.Tasks.Task[ ] tasks, System.Int32 millisecondsTimeout, System.Threading.CancellationToken cancellationToken) [0x001c8] in <787acc3c9a4c471ba7d971300105af24>:0
at System.Threading.Tasks.Task.WaitAll (System.Threading.Tasks.Task[ ] tasks, System.Int32 millisecondsTimeout) [0x00000] in <787acc3c9a4c471ba7d971300105af24>:0
at System.Threading.Tasks.Task.WaitAll (System.Threading.Tasks.Task[ ] tasks) [0x00000] in <787acc3c9a4c471ba7d971300105af24>:0
at Burst.Compiler.IL.Hashing.CacheBuilder.ILHasher.HashImpl () [0x00243] in <772865cdae2d4bff9c305a06338cabcf>:0
at Burst.Compiler.IL.Hashing.CacheBuilder.ILHasher.HashAssembly (System.String filePath, System.Threading.Tasks.TaskFactory taskFactory, Burst.Compiler.TargetFramework targetFramework) [0x00009] in <772865cdae2d4bff9c305a06338cabcf>:0
— End of inner exception stack trace —
at Burst.Compiler.IL.Hashing.CacheBuilder.ILHasher.HashAssembly (System.String filePath, System.Threading.Tasks.TaskFactory taskFactory, Burst.Compiler.TargetFramework targetFramework) [0x0002e] in <772865cdae2d4bff9c305a06338cabcf>:0
at Burst.Compiler.IL.Hashing.CacheRuntime.HashCacheLoader.CreateHashingResult (Mono.Cecil.AssemblyNameReference assemblyNameReference, Burst.Compiler.IL.AssemblyLoader assemblyLoader, Burst.Compiler.IL.Helpers.DebugLogWriter debugLogWriter) [0x001b9] in <772865cdae2d4bff9c305a06338cabcf>:0
at Burst.Compiler.IL.Hashing.CacheRuntime.HashCacheAssemblyStore.GetAssemblyState (System.String assemblyName, Burst.Compiler.IL.AssemblyLoader assemblyLoader) [0x000a0] in <772865cdae2d4bff9c305a06338cabcf>:0
at Burst.Compiler.IL.Server.EntryPointMethodFinder.LoadAllAssemblyReferences (Mono.Cecil.AssemblyDefinition asmDef, System.Collections.Generic.Dictionary2[TKey,TValue] visited, System.Collections.Generic.Dictionary2[TKey,TValue] jobProducers, Burst.Compiler.IL.Hashing.CacheRuntime.HashCacheAssemblyStore assemblyStore, Burst.Compiler.IL.AssemblyLoader assemblyLoader) [0x00025] in <772865cdae2d4bff9c305a06338cabcf>:0
at Burst.Compiler.IL.Server.EntryPointMethodFinder.LoadAllAssemblyReferences (Mono.Cecil.AssemblyDefinition asmDef, System.Collections.Generic.Dictionary2[TKey,TValue] visited, System.Collections.Generic.Dictionary2[TKey,TValue] jobProducers, Burst.Compiler.IL.Hashing.CacheRuntime.HashCacheAssemblyStore assemblyStore, Burst.Compiler.IL.AssemblyLoader assemblyLoader) [0x001e3] in <772865cdae2d4bff9c305a06338cabcf>:0
at Burst.Compiler.IL.Server.EntryPointMethodFinder.FindEntryPoints (System.String[ ] rootAssemblyNames, Burst.Compiler.IL.Hashing.CacheRuntime.HashCacheAssemblyStore assemblyStore, Burst.Compiler.IL.AssemblyLoader assemblyLoader, Burst.Compiler.IL.NativeCompilerOptions options, Burst.Compiler.IL.Server.ProfileDelegate profileCallback, System.Boolean includeRootAssemblyReferences, System.Boolean splitTargets) [0x00071] in <772865cdae2d4bff9c305a06338cabcf>:0
at Burst.Compiler.IL.Server.CompilerServer+<>c__DisplayClass18_1.b__0 (Burst.Compiler.IL.Server.Caching.CacheManager cacheManager) [0x0005e] in <772865cdae2d4bff9c305a06338cabcf>:0
at Burst.Compiler.IL.Server.CompilerServer+<>c__DisplayClass26_01[TResult].<RunTask>b__0 () [0x00145] in <772865cdae2d4bff9c305a06338cabcf>:0 at Burst.Compiler.IL.Server.CompilerServer.RunTask[TResult] (Burst.Compiler.IL.Server.TargetKey target, System.String taskName, System.String[ ] assemblyFolders, System.Threading.CancellationToken cancellationToken, System.Func2[T,TResult] function) [0x00131] in <772865cdae2d4bff9c305a06338cabcf>:0
at Burst.Compiler.IL.Server.CompilerServer.FindMethods (Burst.Compiler.IL.Server.CompilerServerOptions options, Burst.Compiler.IL.Aot.AotCompilerOptions aotOptions, Burst.Compiler.IL.Server.TargetKey target, Burst.Compiler.IL.Server.Caching.CacheManager cacheManager, Burst.Compiler.IL.CompilerStatistics stats, System.Threading.CancellationToken cancellationToken) [0x00299] in <772865cdae2d4bff9c305a06338cabcf>:0
at Burst.Compiler.IL.Server.CompilerServer+<>c__DisplayClass26_01[TResult].<RunTask>b__0 () [0x00145] in <772865cdae2d4bff9c305a06338cabcf>:0 at Burst.Compiler.IL.Server.CompilerServer.RunTask[TResult] (Burst.Compiler.IL.Server.TargetKey target, System.String taskName, System.String[ ] assemblyFolders, System.Threading.CancellationToken cancellationToken, System.Func2[T,TResult] function) [0x00131] in <772865cdae2d4bff9c305a06338cabcf>:0
at Burst.Compiler.IL.Server.CompilerServer.Compile (Burst.Compiler.IL.Server.CompilerServerOptions options, Burst.Compiler.IL.Server.CompilationMessageStreamer streamer, System.Threading.CancellationToken cancellationToken) [0x001af] in <772865cdae2d4bff9c305a06338cabcf>:0
While compiling job:
>> On a build, it ends with the following error:
Build completed with a result of ‘Failed’ in 19 seconds (19015 ms)
Building Library\Bee\artifacts\WinPlayerBuildProgram\ManagedStripped failed with output:
E:\Program Files\Unity\Hub\Editor\2022.3.10f1\Editor\Data\il2cpp\build\deploy\UnityLinker.exe @Library \Bee\artifacts\rsp\2404935537107949824.rsp
Fatal error in Unity CIL Linker
Mono.Linker.LinkerFatalErrorException: ILLink: error IL1005: Peak.Can.Basic.Worker…cctor(): Error processing method ‘Peak.Can.Basic.Worker…cctor()’ in assembly ‘PCANBasic.NET.dll’
—> System.NullReferenceException: Object reference not set to an instance of an object.
at Mono.Linker.Dataflow.ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForCallSite(LinkContext context, MethodReference calledMethod)
at Mono.Linker.Steps.MarkStep.MarkInstruction(Instruction instruction, MethodDefinition method, Boolean& requiresReflectionMethodBodyScanner)
at Mono.Linker.Steps.MarkStep.MarkMethodBody(MethodBody body)
at Unity.Linker.Steps.UnityMarkStep.MarkMethodBody(MethodBody body)
at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method, DependencyInfo& reason)
at Unity.Linker.Steps.UnityMarkStep.ProcessMethod(MethodDefinition method, DependencyInfo& reason)
at Mono.Linker.Steps.MarkStep.ProcessQueue()
— End of inner exception stack trace —
at Mono.Linker.Steps.MarkStep.ProcessQueue()
at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue()
at Mono.Linker.Steps.MarkStep.Process()
at Unity.Linker.Steps.UnityMarkStep.Process(LinkContext context)
at Unity.Linker.UnityPipeline.ProcessStep(LinkContext context, IStep step)
at Mono.Linker.Pipeline.Process(LinkContext context)
at Unity.Linker.UnityDriver.UnityRun(UnityLinkContext context, UnityPipeline p, LinkRequest linkerOptions, TinyProfiler2 tinyProfiler, ILogger customLogger)
at Unity.Linker.UnityDriver.RunDriverWithoutErrorHandling(TinyProfiler2 tinyProfiler, ILogger customLogger)
at Unity.Linker.UnityDriver.RunDriverWithoutErrorHandling()
at Unity.Linker.UnityDriver.RunDriver()
UnityEditor.GenericMenu:CatchMenu (object,string[ ],int)
I already tried adding dll’s and much more to the root and/or assets path. But this did not change anything.
Trying with link.xml didn’t work either.
Right now, the best solution would be to separate this into a dedicated application and communicate via sockets, but this would increase the overhead and error-proneness.
Would anyone think of a way to solve this without a mono build. Are there burst settings that I am not aware of?
Would appreciate any help.
Thanks.
These errors generally mean that something is wrong with that DLL. Do you have source code to it? You could try recompiling it against .NET Standard 2.1 if you do.
Otherwise, you could also try running PEVerify tool on it to see if it finds any issues.
Thanks for your answer.
Source Code
Sadly, I don’t have the source code for it.
When I decompile the .dll (just to find a clue) with dotPeek I can see that the code is obfuscated.
Additionally, in the methods, it writes only: // ISSUE: unable to decompile the method.
PEVerify tool
Unfortunately, I do not know really how to use it. But I have run two options.
- Option /md
Microsoft (R) .NET Framework PE Verifier. Version 4.0.30319.0
Copyright (c) Microsoft Corporation. All rights reserved.
[MD]: Error (Structural): Table=0x00000000, Col=0x00000004, Row=0x00000001, has an invalid GUID offset.
[MD]: Error (Structural): Table=0x00000001, Col=0x00000000, Row=0x00000084, has coded rid out of range.
[MD]: Error (Structural): Table=0x00000001, Col=0x00000000, Row=0x0000008b, has coded rid out of range.
3 Error(s) Verifying E:\PCANBasic\lib\netstandard2.0\PCANBasic.NET.dll
- Option /il
I don’t know if I used the tool correctly.
I am open to advice.
Thanks
The /md option shows that the DLL contains invalid metadata. Unfortunately since both IL2CPP and Burst need to read this metadata, they have to assume the DLLs are valid and if they’re not things go wrong (like in this case).
Since you don’t have the the source code, I would try contacting the authors of this DLL and asking them to fix the metadata entries. It’s likely their obfuscator that is messing it up.
Unfortunately I don’t think you have any other options, if you need to use this DLL