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