我正在尝试使用Windows Runtime组件在我的Javascript UWP应用程序和我编写的C#逻辑之间提供互操作性。如果我将最小版本设置为Fall Creator's Update(构建16299,需要使用.NET Standard 2.0库),则在尝试调用简单方法时会出现以下错误:
如果我将此代码使用 Creator 的更新版(15063)作为最低要求来运行,则该代码可以正常运行。
我创建了一个 Github 仓库,其中包含一个样本解决方案,当我在本地运行时会生成错误。
以下是 main.js 的内容。尝试运行 getExample 函数时会出现错误:
Unhandled exception at line 3, column 1 in ms-appx://ed2ecf36-be42-4c35-af69-93ec1f21c283/js/main.js
0x80131040 - JavaScript runtime error: Unknown runtime error
如果我将此代码使用 Creator 的更新版(15063)作为最低要求来运行,则该代码可以正常运行。
我创建了一个 Github 仓库,其中包含一个样本解决方案,当我在本地运行时会生成错误。
以下是 main.js 的内容。尝试运行 getExample 函数时会出现错误:
// Your code here!
var test = new RuntimeComponent1.Class1;
test.getExample().then(result => {
console.log(result);
});
这就是 Class1.cs 的样子:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Text;
using System.Threading.Tasks;
using Windows.Foundation;
namespace RuntimeComponent1
{
public sealed class Class1
{
public IAsyncOperation<string> GetExample()
{
return AsyncInfo.Run(token => Task.Run(getExample));
}
private async Task<string> getExample()
{
return "It's working";
}
}
}
我想不出比这更简单的测试用例了 - 我没有安装NuGet包或其他任何东西。我不知道可能是什么原因导致这种情况。还有其他人有什么想法吗?