I'm attempting to access a C# component in UWP, but I get an unhelpful error when doing so: WinRTError: Unknown runtime error. Why does this error occur, and how can I stop it?
I'm using Windows 10, VS 2017, and building my project to meet the minimum version of 10.0.16299.0
Here's a MVCE showing the behavior: https://github.com/re-jim/UWPComponentSample
The C# component is set as a reference in my Javascript component.
Javascript:
The below function triggers the C# component, which should zip a directory
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)
}
}
I've console.logged the component and the method I intend to use to show that exists:
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);
}
}
}
}
I don't see the output from Debug.WriteLine in my output
The code inside of ZipDirectory() doesn't seem to be causing the error. I replaced the function with:
public static string ZipDirectory(){
return "hello world"
}
after also editing the javascript function call to match, And that gives me the same error as below.
Stack trace:
"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)"
