-
-
Notifications
You must be signed in to change notification settings - Fork 565
Open
Labels
Description
Description
When attempting to use Harmony with Unity, if the Burst Compiler is used by the project, it will fail to operate.
Reproduction
- Create a VRChat World project
- Close Unity
- Swap
0Harmony.dllunderPackages/com.vrchat.base/Runtime/VRCSDK/Plugins/Harmony/0Harmony.dllwithin the project directory with the fat dll from Harmony 4.2.1, variantnet472. - Open Unity
Expectation
- Nothing happens
Result
- The VRC SDK breaks
- The following is output to the console:
Failed to find entry-points:
System.Exception: Error while loading assembly references for UdonSharp.Editor ---> System.Exception: Error while hashing assembly /Packages/com.vrchat.base/Runtime/VRCSDK/Plugins/Harmony/0Harmony.dll ---> System.AggregateException: One or more errors occurred. (Error while hashing type reference '1000136' in assembly '0Harmony.dll') ---> System.Exception: Error while hashing type reference '1000136' in assembly '0Harmony.dll' ---> System.BadImageFormatException: Read out of bounds.
at System.Reflection.Throw.OutOfBounds () [0x00005] in <dd9f65e0a5bd49ea8090db671948b5fc>:0
at System.Reflection.Internal.MemoryBlock.PeekHeapReference (System.Int32 offset, System.Boolean smallRefSize) [0x0000b] in <dd9f65e0a5bd49ea8090db671948b5fc>:0
at System.Reflection.Metadata.Ecma335.AssemblyRefTableReader.GetName (System.Int32 rowId) [0x0000b] in <dd9f65e0a5bd49ea8090db671948b5fc>:0
at System.Reflection.Metadata.AssemblyReference.get_Name () [0x00020] in <dd9f65e0a5bd49ea8090db671948b5fc>:0
at Burst.Compiler.IL.Hashing.CacheBuilder.Util.SrmExtensions.GetAssemblyNameReference (System.Reflection.Metadata.AssemblyReference& assemblyReference, System.Reflection.Metadata.MetadataReader metadataReader) [0x00000] in <f26dfc19a37a442ea317a7ab78395fa6>:0
at Burst.Compiler.IL.Hashing.CacheBuilder.Util.CachingMetadataReader.GetAssemblyNameReferenceImpl (System.Reflection.Metadata.AssemblyReferenceHandle handle) [0x0000d] in <f26dfc19a37a442ea317a7ab78395fa6>:0
at System.Collections.Concurrent.ConcurrentDictionary`2[TKey,TValue].GetOrAdd (TKey key, System.Func`2[T,TResult] valueFactory) [0x00034] in <b904252b6b4e4277834bcca7e51f318d>:0
at Burst.Compiler.IL.Hashing.CacheBuilder.Util.CachingMetadataReader.GetAssemblyNameReference (System.Reflection.Metadata.AssemblyReferenceHandle handle) [0x00000] in <f26dfc19a37a442ea317a7ab78395fa6>:0
at Burst.Compiler.IL.Hashing.CacheBuilder.Util.SrmExtensions.WriteAssemblyNameTo (System.Reflection.Metadata.TypeReference& typeReference, Burst.Compiler.IL.Helpers.Hash128Builder builder, Burst.Compiler.IL.Hashing.CacheBuilder.Util.CachingMetadataReader reader, Burst.Compiler.TargetFramework targetFramework) [0x00037] in <f26dfc19a37a442ea317a7ab78395fa6>:0
at Burst.Compiler.IL.Hashing.CacheBuilder.ILHasher.HashTypeReferenceImpl (System.Reflection.Metadata.TypeReferenceHandle typeReferenceHandle) [0x00089] in <f26dfc19a37a442ea317a7ab78395fa6>:0
at Burst.Compiler.IL.Hashing.CacheBuilder.ILHasher.HashTypeReference (System.Reflection.Metadata.TypeReferenceHandle typeReferenceHandle) [0x00000] in <f26dfc19a37a442ea317a7ab78395fa6>:0
--- End of inner exception stack trace ---
at Burst.Compiler.IL.Hashing.CacheBuilder.ILHasher.HashTypeReference (System.Reflection.Metadata.TypeReferenceHandle typeReferenceHandle) [0x00031] in <f26dfc19a37a442ea317a7ab78395fa6>:0
at Burst.Compiler.IL.Hashing.CacheBuilder.ILHasher+<>c__DisplayClass14_0.<HashImpl>b__6 (System.Reflection.Metadata.TypeReferenceHandle typeReferenceHandle, System.Threading.Tasks.ParallelLoopState loopState, System.Int64 i) [0x00000] in <f26dfc19a37a442ea317a7ab78395fa6>:0
at Burst.Compiler.IL.Hashing.CacheBuilder.ILHasher.ForEach[T] (System.Collections.Generic.IEnumerable`1[T] elements, System.Action`3[T1,T2,T3] callback) [0x00018] in <f26dfc19a37a442ea317a7ab78395fa6>:0
at Burst.Compiler.IL.Hashing.CacheBuilder.ILHasher+<>c__DisplayClass14_0.<HashImpl>b__1 () [0x00000] in <f26dfc19a37a442ea317a7ab78395fa6>:0
at System.Threading.Tasks.Task.InnerInvoke () [0x0000f] in <b904252b6b4e4277834bcca7e51f318d>:0
at System.Threading.Tasks.Task.Execute () [0x00000] in <b904252b6b4e4277834bcca7e51f318d>: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 <b904252b6b4e4277834bcca7e51f318d>:0
at System.Threading.Tasks.Task.WaitAll (System.Threading.Tasks.Task[] tasks, System.Int32 millisecondsTimeout) [0x00000] in <b904252b6b4e4277834bcca7e51f318d>:0
at System.Threading.Tasks.Task.WaitAll (System.Threading.Tasks.Task[] tasks) [0x00000] in <b904252b6b4e4277834bcca7e51f318d>:0
at Burst.Compiler.IL.Hashing.CacheBuilder.ILHasher.HashImpl () [0x00243] in <f26dfc19a37a442ea317a7ab78395fa6>:0
at Burst.Compiler.IL.Hashing.CacheBuilder.ILHasher.HashAssembly (System.String filePath, System.Threading.Tasks.TaskFactory taskFactory, Burst.Compiler.TargetFramework targetFramework) [0x00009] in <f26dfc19a37a442ea317a7ab78395fa6>: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 <f26dfc19a37a442ea317a7ab78395fa6>: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 <f26dfc19a37a442ea317a7ab78395fa6>:0
at Burst.Compiler.IL.Hashing.CacheRuntime.HashCacheAssemblyStore.GetAssemblyState (System.String assemblyName, Burst.Compiler.IL.AssemblyLoader assemblyLoader) [0x000a0] in <f26dfc19a37a442ea317a7ab78395fa6>:0
at Burst.Compiler.IL.Server.EntryPointMethodFinder.LoadAllAssemblyReferences (Mono.Cecil.AssemblyDefinition asmDef, System.Collections.Generic.Dictionary`2[TKey,TValue] visited, System.Collections.Generic.Dictionary`2[TKey,TValue] jobProducers, Burst.Compiler.IL.Hashing.CacheRuntime.HashCacheAssemblyStore assemblyStore, Burst.Compiler.IL.AssemblyLoader assemblyLoader) [0x00025] in <f26dfc19a37a442ea317a7ab78395fa6>:0
at Burst.Compiler.IL.Server.EntryPointMethodFinder.LoadAllAssemblyReferences (Mono.Cecil.AssemblyDefinition asmDef, System.Collections.Generic.Dictionary`2[TKey,TValue] visited, System.Collections.Generic.Dictionary`2[TKey,TValue] jobProducers, Burst.Compiler.IL.Hashing.CacheRuntime.HashCacheAssemblyStore assemblyStore, Burst.Compiler.IL.AssemblyLoader assemblyLoader) [0x001de] in <f26dfc19a37a442ea317a7ab78395fa6>: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 <f26dfc19a37a442ea317a7ab78395fa6>:0
--- End of inner exception stack trace ---
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) [0x00094] in <f26dfc19a37a442ea317a7ab78395fa6>:0
at Burst.Compiler.IL.Server.CompilerServer+<>c__DisplayClass18_1.<FindMethods>b__0 (Burst.Compiler.IL.Server.Caching.CacheManager cacheManager) [0x0005e] in <f26dfc19a37a442ea317a7ab78395fa6>:0
at Burst.Compiler.IL.Server.CompilerServer+<>c__DisplayClass26_0`1[TResult].<RunTask>b__0 () [0x00145] in <f26dfc19a37a442ea317a7ab78395fa6>: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.Func`2[T,TResult] function) [0x00131] in <f26dfc19a37a442ea317a7ab78395fa6>: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 <f26dfc19a37a442ea317a7ab78395fa6>:0
at Burst.Compiler.IL.Server.CompilerServer+<>c__DisplayClass26_0`1[TResult].<RunTask>b__0 () [0x00145] in <f26dfc19a37a442ea317a7ab78395fa6>: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.Func`2[T,TResult] function) [0x00131] in <f26dfc19a37a442ea317a7ab78395fa6>: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 <f26dfc19a37a442ea317a7ab78395fa6>:0
Environment
- Host: MacBook Air M2, 24GB RAM
- OS: macOS Sequoia 15.6
- Target Application: Unity Editor 2022.3.22f1
- Project Type: VRChat SDK (World)
- Harmony Version: 4.2.1
- Net Framework Version: 4.7.2
- Also tested with 4.8 & 4.5.2 with similar results
Additional Notes
- The VRCSDK relies on Harmony for the Client Sim/UDON, as it is runtime patching the editor itself, not the game or its scripts. The version included is an old local build from its original maintainer that fixed some localization issues at the time, targeting Net Framework 4.5.
- The SDK also relies on Burst compilation and as such it cannot be removed.
- The metadata issues are reported with
PEVerify.exe 0Harmony.dll /MD. When ran against the copy provided by the SDK, it reports that all classes and methods are verified,confirming this issue is unique to provided release builds. The following is the output of the same command when ran against the release builds of Harmony:
Microsoft (R) .NET Framework PE Verifier. Version 4.0.30319.0
Copyright (c) Microsoft Corporation. All rights reserved.
[MD]: Error (Structural): Table=0x00000001, Col=0x00000000, Row=0x00000138, has coded rid out of range.
[MD]: Error (Structural): Table=0x00000001, Col=0x00000000, Row=0x00000140, has coded rid out of range.
[MD]: Error (Structural): Table=0x00000001, Col=0x00000000, Row=0x00000143, has coded rid out of range.
[MD]: Error (Structural): Table=0x00000001, Col=0x00000000, Row=0x00000146, has coded rid out of range.
[MD]: Error (Structural): Table=0x00000001, Col=0x00000000, Row=0x0000014b, has coded rid out of range.
[MD]: Error (Structural): Table=0x00000001, Col=0x00000000, Row=0x0000014e, has coded rid out of range.
[MD]: Error (Structural): Table=0x00000001, Col=0x00000000, Row=0x00000153, has coded rid out of range.
[MD]: Error (Structural): Table=0x00000001, Col=0x00000000, Row=0x0000015a, has coded rid out of range.
[MD]: Error (Structural): Table=0x00000001, Col=0x00000000, Row=0x0000015b, has coded rid out of range.
[MD]: Error (Structural): Table=0x00000001, Col=0x00000000, Row=0x0000015c, has coded rid out of range.
10 Error(s) Verifying D:\Shared\0Harmony.dll
- The Unity Forum post which mentions this issue notes that it does not appear in local builds from the main branch, suggesting there may be an issue with the build pipeline?
Reactions are currently unavailable