Я пытаюсь получить доступ к компоненту C # в UWP, но при этом я получаю бесполезную ошибку: WinRTError: Unknown runtime error
.Почему возникает эта ошибка, и как я могу ее остановить?
Я использую Windows 10, VS 2017 и строю свой проект, чтобы соответствовать минимальной версии 10.0.16299.0
Вот MVCE , показывающий поведение: https://github.com/re-jim/UWPComponentSample
Компонент C # установлен в качестве ссылки в моем компоненте Javascript.
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 компонент и метод, который я намерен использовать, чтобы показать, что существует:
![enter image description here](https://i.stack.imgur.com/I1FII.png)
C #
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)"