2

我在 Unity3d 项目中使用的类库中使用 Google.ProtocolBuffersLite。当尝试在 IOS 应用程序的 myClass.cs 中使用 ParseFrom(System.Byte[] data) 函数时,出现以下异常:

---> System.TypeInitializationException: An exception was thrown by the type initializer for System.Collections.Generic.EqualityComparer`1 
---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. 
---> System.ExecutionEngineException: Attempting to JIT compile method 'System.Collections.Generic.GenericEqualityComparer`1<Google.ProtocolBuffers.ExtensionRegistry/ExtensionIntPair>:.ctor ()' while running with --aot-only.

  at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
  at System.Reflection.MonoCMethod.Invoke (BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
  at System.Reflection.ConstructorInfo.Invoke (System.Object[] parameters) [0x00000] in <filename unknown>:0 
  at System.Activator.CreateInstance (System.Type type, Boolean nonPublic) [0x00000] in <filename unknown>:0 
  at System.Activator.CreateInstance (System.Type type) [0x00000] in <filename unknown>:0 
  at System.Collections.Generic.EqualityComparer`1[Google.ProtocolBuffers.ExtensionRegistry+ExtensionIntPair]..cctor () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Collections.Generic.Dictionary`2[Google.ProtocolBuffers.ExtensionRegistry+ExtensionIntPair,Google.ProtocolBuffers.IGeneratedExtensionLite].Init (Int32 capacity, IEqualityComparer`1 hcp) [0x00000] in <filename unknown>:0 
  at System.Collections.Generic.Dictionary`2[Google.ProtocolBuffers.ExtensionRegistry+ExtensionIntPair,Google.ProtocolBuffers.IGeneratedExtensionLite]..ctor () [0x00000] in <filename unknown>:0 
  at Google.ProtocolBuffers.ExtensionRegistry..cctor () [0x00000] in <filename unknown>:0  Exception.Message: An exception was thrown by the type initializer for Google.ProtocolBuffers.ExtensionRegistry
at Google.ProtocolBuffers.AbstractBuilderLite`2[TMessage,TBuilder].MergeFrom (System.Byte[] data) [0x00000] in <filename unknown>:0 

使用 protocolBuffersLite 的过程是:

  1. 添加选项 optimize_for = LITE_RUNTIME; 在我的 .proto 课程中
  2. 使用该 .proto 类和 Google.ProtocolBuffers.dll 版本 net20 生成 .cs 类
  3. 将 .cs 类和 Google.ProtocolBuffersLite.dll 添加到我的库 csharp proj
  4. 使用 monoDevelop 2.8.2 编译
  5. 将 myLibraryThatUseProtocol.dll 和 Google.ProtocolBuffersLite.dll 移动到 myUnity3d 项目
  6. 在 Unity3D->Build Settings->IOS->PlayerSettings 我使用:

    Api 兼容级别:.net 2.0 子集

    Aot 编译选项:空

    剥离级别:禁用

  7. 在 Unity3d 中构建应用程序(版本 4.2.0)
  8. 在 Xcode 中运行应用程序
我将不胜感激有人可以提供的任何帮助。

4

0 回答 0