<p>This is my first time playing with K8s api/client. I am trying to watch for events in all namespaces.
Below is the method, on running it prints:</p>
<blockquote>
<p>Exception : Object reference not set to an instance of an object.<br />
Closed</p>
</blockquote>
<p>There aren't enough docs on how to use the <a href="https://github.com/kubernetes-client/csharp/tree/master/src/KubernetesClient" rel="nofollow noreferrer">C# client library</a>. Can someone help me in understanding what I am doing wrong?</p>
<p>This is the method:</p>
<pre><code>    public async Task Temp() {
        var config = KubernetesClientConfiguration.BuildConfigFromConfigFile();
        IKubernetes client = new Kubernetes(config);
        var resourceVersion = client.ListEventForAllNamespaces().ResourceVersion();
        var path = $&quot;api/v1/events&quot;;
        // wait for events
        while (true)
        {
            var eventsWatcher = await client.WatchObjectAsync&lt;V1EventList&gt;(
            timeoutSeconds: int.MaxValue,
            path: path,
            resourceVersion: resourceVersion,
            onEvent: new Action&lt;WatchEventType, V1EventList&gt;((x, y) =&gt;
            {
                Console.WriteLine(x.ToString());
            }),
            onClosed: new Action(() =&gt;
            {
                Console.WriteLine(&quot;Closed&quot;);
            }),
            onError: new Action&lt;Exception&gt;((e) =&gt;
            {
                Console.WriteLine($&quot;Exception : {e.Message}&quot;);
            }));

        
            Thread.Sleep(1000);
        }
    }
</code></pre>
<p>On a side note, I am able to watch locally using http://localhost:8080/api/v1/events?watch=1&amp;resourceVersion=27958468 after kubectl proxy</p>

Ajay Sainy
<p>Found the issue. I was using the wrong &quot;path&quot;. Instead of api/v1/events it should be <strong>api/v1/watch/events</strong>. The NullReferenceException was happening within the library's <a href="https://github.com/kubernetes-client/csharp/blob/master/src/KubernetesClient/Watcher.cs" rel="nofollow noreferrer">watcher.cs line 149</a></p>
<p><a href="https://i.stack.imgur.com/rrJ7q.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rrJ7q.png" alt="enter image description here" /></a></p>
