导入Unity时为Unity创建托管DLL失败并出现错误

导入Unity时为Unity创建托管DLL失败并出现错误

本文介绍了导入Unity时为Unity创建托管DLL失败并出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to build two managed DLLs for Unity from C# scripts with Visual Studio 2015. One DLL is the actual asset and one contains the editor integration.

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

So I have a VS solution with two projects:

MyProduct
MyProduct Editor

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

First I compile MyProduct and it builds MyProduct.DLL from it (with Debug config). MyProduct Editor then references that DLL because there are classes in it that it needs. I then build the MyProductEditor.dll

然后我想在Unity中对其进行测试,因此我将其导入,但是随后在Unity中出现以下错误,并且它不起作用:

I then want to test them in Unity, so I import them but then I get the following error in Unity and it's not working:

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.

Does anyone know why this happens? Because I have no clue what's going on or what could be wrong. I'm using Unity 5.2.2f1.

推荐答案

看看此处.

这篇关于导入Unity时为Unity创建托管DLL失败并出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 22:13