title: How to catch own C# events in Javascript code in Win8 Metro apps?
body: <p>I found examples with google how to implement event listeners to C# events in Javascript code, but somehow in my case, nothing seems to work.</p>
  
  <p>My C# class:</p>
  
  <pre><code>namespace Engine
  {
  
      public delegate void EventDelegate();
  
      public sealed class MyClass;
      {
          public event EventDelegate nowEvent;
  
          public void runJobs()
          {
             if (nowEvent == null)
             {
               Debug.WriteLine("What? Nobody subscribed???");
             }
          }
      }
  }
  </code></pre>
  
  <p>Javascript side:</p>
  
  <pre><code>WinJS.Namespace.define("App", {
      myclass: new Engine.MyClass()
  });
  
  App.myclass.addEventListener("nowEvent", function onReady() {
              console.error("hello");
          });
  
  App.myclass.runJobs();
  </code></pre>
  
  <p>After attaching the onReady function to the nowEvent event and running runJobs(), the MyClass.nowEvent is null.</p>
  
  <p>What is the working syntax to subscribe to C# events of own classes in JS. Any ideas?</p>
  
  <p>EDIT: After Gambit's advise:</p>
  
  <pre><code>App.myclass.addEventListener("nowevent", function onReady() {
                  console.error("hello");
              });
  </code></pre>
  
  <p>The event pointer is not null anymore, but when I fire the event, I get:</p>
  
  <p>A first chance exception of type 'System.InvalidCastException' occurred in Engine.winmd</p>