我've written an extremely simple dll to figure out how it works. But I'得到了那个丑陋的错误 .
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
}
}
dll在Visual Studio中编译为x64(因为Unity是64位) .
该DLL已被复制到Assets \ Plugins \文件夹中(每次构建后自动) .
Unity并没有抱怨任何编译问题......
源dll中没有 PresentationCore
引用 - 它不是必需的 .
我试过添加它(v4.0.0.0),但它没有任何区别 .
我在Unity中启用了 Experimental (.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 type:member: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)
我究竟做错了什么?我需要做什么?