主要问题
stdout: Fatal error in Unity CIL Linker Mono.Linker.MarkException: Error processing method: 'System.Byte[] GetCheckCode/CRC32::ComputeHash(System.IO.Stream)' in assembly: 'Assembly-CSharp.dll' ---> System.NotImplementedException: Array错误原因
直接原因:UnityLinker 在分析
Assembly-CSharp.dll中的方法GetCheckCode/CRC32::ComputeHash(Stream)时,尝试读取该方法内的局部常量(local constant),但这个常量是一个数组(比如byte[])。该版本的 Mono.Cecil 的ReadPrimitiveValue方法没有实现对Array类型的处理,直接抛出了NotImplementedException。
解决方案
把ComputeHash方法中的局部数组改为类的静态只读字段,这样就不会产生“局部常量”的调试元数据。
// 修改前(局部常量) public byte[] ComputeHash(Stream stream) { byte[] table = new byte[] { 1, 2, 3, ... }; // ... } // 修改后(静态只读字段) private static readonly byte[] CrcTable = new byte[] { 1, 2, 3, ... }; public byte[] ComputeHash(Stream stream) { // 直接使用 CrcTable // ... }