在导入Unity时,为Unity创建托管DLL失败,并显示错误

时间:2015-11-19 08:16:58

标签: c# visual-studio dll unity3d

我正在尝试使用Visual Studio 2015从C#脚本为Unity构建两个托管DLL。一个DLL是实际资产,一个包含编辑器集成。

所以我有两个项目的VS解决方案:

MyProduct
MyProduct Editor

首先我编译MyProduct并从中构建MyProduct.DLL(使用Debug配置)。 MyProduct编辑器然后引用该DLL,因为它有所需的类。然后我构建MyProductEditor.dll

然后我想在Unity中测试它们,所以我导入它们然后我在Unity中得到以下错误并且它不起作用:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
  at Mono.Cecil.BaseAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference name, Mono.Cecil.ReaderParameters parameters) [0x00000] in <filename unknown>:0 
  at Mono.Cecil.BaseAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference name) [0x00000] in <filename unknown>:0 
  at Mono.Cecil.DefaultAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference name) [0x00000] in <filename unknown>:0 
  at Mono.Cecil.MetadataResolver.Resolve (Mono.Cecil.TypeReference type) [0x00000] in <filename unknown>:0 
  at Mono.Cecil.ModuleDefinition.Resolve (Mono.Cecil.TypeReference type) [0x00000] in <filename unknown>:0 
  at Mono.Cecil.TypeReference.Resolve () [0x00000] in <filename unknown>:0 
  at AssemblyUpdater.Steps.MemberReferenceReplacer.MemberReferenceReplacementForProperty (Mono.Cecil.MethodReference method) [0x00000] in <filename unknown>:0 
  at AssemblyUpdater.Steps.MemberReferenceReplacer.MemberReferenceReplacementFor (Mono.Cecil.MethodReference methodReference) [0x00000] in <filename unknown>:0 
  at AssemblyUpdater.Steps.MemberReferenceReplacer.Visit (Mono.Cecil.MethodReference methodReference, Unity.Cecil.Visitor.Context context) [0x00000] in <filename unknown>:0 
  at Unity.Cecil.Visitor.Visitor.Visit (Mono.Cecil.Cil.Instruction instruction, Unity.Cecil.Visitor.Context context) [0x00000] in <filename unknown>:0 
  at Unity.Cecil.Visitor.Visitor.Visit (Mono.Cecil.Cil.MethodBody methodBody, Unity.Cecil.Visitor.Context context) [0x00000] in <filename unknown>:0 
  at Unity.Cecil.Visitor.Visitor.Visit (Mono.Cecil.MethodDefinition methodDefinition, Unity.Cecil.Visitor.Context context) [0x00000] in <filename unknown>:0 
  at Unity.Cecil.Visitor.Visitor.Visit (Mono.Cecil.TypeDefinition typeDefinition, Unity.Cecil.Visitor.Context context) [0x00000] in <filename unknown>:0 
  at Unity.Cecil.Visitor.Visitor.Visit (Mono.Cecil.ModuleDefinition moduleDefinition, Unity.Cecil.Visitor.Context context) [0x00000] in <filename unknown>:0 
  at Unity.Cecil.Visitor.Visitor.Visit (Mono.Cecil.AssemblyDefinition assemblyDefinition, Unity.Cecil.Visitor.Context context) [0x00000] in <filename unknown>:0 
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.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.MonoMethod.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.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <filename unknown>:0 
  at Unity.Cecil.Visitor.Visitor.Visit[AssemblyDefinition] (Mono.Cecil.AssemblyDefinition node, Unity.Cecil.Visitor.Context context) [0x00000] in <filename unknown>:0 
  at Unity.Cecil.Visitor.Extensions.DoAccept[AssemblyDefinition] (Mono.Cecil.AssemblyDefinition definition, Unity.Cecil.Visitor.Visitor visitor) [0x00000] in <filename unknown>:0 
  at Unity.Cecil.Visitor.Extensions.Accept (Mono.Cecil.AssemblyDefinition assemblyDefinition, Unity.Cecil.Visitor.Visitor visitor) [0x00000] in <filename unknown>:0 
  at AssemblyUpdater.Steps.AssemblyUpdaterStepBase.Apply (AssemblyUpdater.Core.AssemblyUpdaterContext context) [0x00000] in <filename unknown>:0 
  at AssemblyUpdater.Core.AssemblyUpdaterPipeline.Run (AssemblyUpdater.Core.AssemblyUpdaterContext context) [0x00000] in <filename unknown>:0 
  at AssemblyUpdater.Application.Program.CheckForObsoleteAPIUsage (AssemblyUpdater.Application.CommandLineSpec config) [0x00000] in <filename unknown>:0 
  at AssemblyUpdater.Application.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0 
UnityEditor.Scripting.APIUpdaterHelper:DoesAssemblyRequireUpgrade(String)

有谁知道为什么会这样?因为我不知道发生了什么或什么可能是错的。我正在使用Unity 5.2.2f1。

1 个答案:

答案 0 :(得分:0)

看看Here

  

该修复程序正被移植到5.2。不知道它是否会产生5.2.3。