我写了一个非常简单的dll来弄清楚它是如何工作的。但是我得到了那个丑陋的错误 dll的来源是
using System;
using System.Threading.Tasks;
namespace TTiles
{
public class Class1
{
private const int DefaultExtent = 4096;
public static int GetNumber()
{
return 5;
}
public static async Task<int> GetNumberAsync()
{
await Task.Delay(TimeSpan.FromSeconds(3.4));
return 5;
}
}
}
Unity脚本基本上只是
using System;
using Mapbox.Platform;
using TTiles;
namespace Assets.Scripts.Cache
{
internal class TRequest : IAsyncRequest
{
#region External Headers - We don't need them!
/*
[DllImport("TTiles")]
private static extern Task<Byte[]> GetTileAsync();
[DllImport("TTiles")]
private static extern int GetNumber();
*/
#endregion
#region Constructor
public TRequest(Action<Response> callback, int timeout)
{
IsCompleted = false;
_callback = callback;
_timeout = timeout;
GetVectorNumberAsync();
}
#endregion
#region Private Methods
private async void GetVectorNumberAsync()
{
try
{
var number = await Class1.GetNumberAsync();
Console.WriteLine(number);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
throw;
}
IsCompleted = true;
}
#endregion
}
}
在Visual Studio中将dll编译为x64(因为Unity是64位) 已将dll复制到Assets \ Plugins \文件夹中(每次构建后自动复制) Unity并没有抱怨编译问题......
源dll中没有PresentationCore
引用 - 它不是必需的。
我试过添加它(v4.0.0.0),但没有区别。
我在Unity中启用了实验(.NET 4.6 Equivalent) 该DLL是使用.NET 4.6构建的。
但是我在运行时遇到了这个错误。
TypeLoadException:无法加载字段'A.cb56c87025be887e2687073fa009b1198:c8f44f8494ce26970d56fa7d1f7c06e04'(1)的类型,原因是:无法加载文件或程序集'PresentationCore,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'或其中一个它的依赖关系。 assembly:presentationCore,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35类型:成员: System.RuntimeType.GetMethodsByName(System.String name,System.Reflection.BindingFlags bindingAttr,System.Boolean ignoreCase,System.RuntimeType reflectType)(at:0) System.RuntimeType.GetMethodCandidates(System.String name,System.Reflection.BindingFlags bindingAttr,System.Reflection.CallingConventions callConv,System.Type [] types,System.Boolean allowPrefixLookup)(at:0) System.RuntimeType.GetMethods(System.Reflection.BindingFlags bindingAttr)(at:0) UnityEditor.Build.BuildPipelineInterfaces.InitializeBuildCallbacks(UnityEditor.Build.BuildPipelineInterfaces + BuildCallbacks findFlags)(at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildPipelineInterfaces.cs:188)
我做错了什么? 我需要做什么?