我正在尝试访问UWP中的C#组件,但这样做时出现无用的错误:WinRTError: Unknown runtime error
。为什么会发生此错误,如何解决?
我正在使用Windows 10,VS 2017,并构建我的项目以满足最低版本10.0.16299.0
这是显示行为的 MVCE :https://github.com/re-jim/UWPComponentSample
将C#组件设置为Javascript组件中的引用。
以下功能触发C#组件,该组件应压缩目录
async zip(content) {
try {
console.log('ZipComponent is ', ZipComponent)
console.log('function is ', ZipComponent.ZipWorker.zipDirectory)
ZipComponent.ZipWorker.zipDirectory(content.dirPath, content.dirPath + '\\file.ezdrm')
} catch (err) {
console.log('err is ',err)
}
}
我已经console.logged我打算用来显示它存在的组件和方法:
using System;
using System.Diagnostics;
using System.IO.Compression;
namespace ZipComponent
{
public sealed class ZipWorker
{
public static void ZipDirectory(string folderPath, string outputFile)
{
try
{
Debug.WriteLine("zippping " + folderPath + " output " + outputFile);
ZipFile.CreateFromDirectory(folderPath, outputFile);
}
catch (Exception e)
{
Debug.Write(e);
}
}
public static void UnzipDirectory(string zipFile, string outputPath)
{
try
{
Debug.WriteLine("unzippping " + zipFile + " output " + outputPath);
ZipFile.ExtractToDirectory(zipFile, outputPath);
}
catch (Exception e)
{
Debug.Write(e);
}
}
}
}
我在输出中看不到Debug.WriteLine的输出
ZipDirectory()
内部的代码似乎没有引起错误。我将功能替换为:
public static string ZipDirectory(){
return "hello world"
}
还要编辑javascript函数调用以使其匹配,这给了我与下面相同的错误。
"WinRTError: Unknown runtime error
at ZipService.prototype.zip (ms-appx://9ecba615-ddcd-4c3c-a8f1-a09e9aac3e60/dist/zip.service.js:12:13)
at Generator.prototype.next (native code)
at onZipRequest (ms-appx://9ecba615-ddcd-4c3c-a8f1-a09e9aac3e60/dist/wrapperMain.js:69:9)
at Generator.prototype.next (native code)
at SafeSubscriber.prototype.__tryOrUnsub (ms-appx://9ecba615-ddcd-4c3c-a8f1-a09e9aac3e60/dist/rxjs/rxjs.umd.js:477:13)
at SafeSubscriber.prototype.next (ms-appx://9ecba615-ddcd-4c3c-a8f1-a09e9aac3e60/dist/rxjs/rxjs.umd.js:415:17)
at Subscriber.prototype._next (ms-appx://9ecba615-ddcd-4c3c-a8f1-a09e9aac3e60/dist/rxjs/rxjs.umd.js:359:9)
at Subscriber.prototype.next (ms-appx://9ecba615-ddcd-4c3c-a8f1-a09e9aac3e60/dist/rxjs/rxjs.umd.js:336:13)
at Subject.prototype.next (ms-appx://9ecba615-ddcd-4c3c-a8f1-a09e9aac3e60/dist/rxjs/rxjs.umd.js:755:17)
at AppShellService.prototype.zipContent (ms-appx://9ecba615-ddcd-4c3c-a8f1-a09e9aac3e60/dist/main.js:197:13)"