Splunk Dev

Why am I getting c# oneshot search exception "Object reference not set to an instance of an object"?

szymon_cwieka
Explorer

Hello,

I got this exception lately, and I have no idea why. 2 days ago everything was fine, and I have absolutely no idea what is going on now. I would be thankful for help with this:

(in image: Form1.cs:line 45 is using (var stream = service.Oneshot(oneshotQuery, outArgs)) )

using Splunk;

private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                var connect = new ServiceArgs
                {
                    Host = "myip",
                    Port = 8089,
                    Scheme = "https"
                };

                Splunk.Service service = new Splunk.Service(connect);

                var oneshot = new Splunk.Client.JobArgs();
                //oneshot.EarliestTime = "2015-08-09 10:25:00";
                //oneshot.LatestTime = "2015-08-09 11:25:00"
                String oneshotQuery = "search * | head 10";

                var outArgs = new JobResultsArgs
                {
                    OutputMode = JobResultsArgs.OutputModeEnum.Xml,
                    Count = 0,
                };

                using (var stream = service.Oneshot(oneshotQuery, outArgs))
                {
                    using (var rr = new ResultsReaderXml (stream))
                    {
                        foreach (var @event in rr)
                        {
                            richTextBox1.Text += "Event:" + Environment.NewLine;
                            foreach (string key in @event.Keys)
                            {
                                richTextBox1.Text += "   " + key + " -> " + @event[key];
                            }
                        }
                    }
                }

                button1.BackColor = Color.Green;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString() ,ex.Message.ToString());
            }

alt text

Tags (3)
0 Karma
1 Solution

szymon_cwieka
Explorer

I just forgot to add service.Login("login", "password"); after Splunk.Service service = new Splunk.Service(connectArgs);
Stupid me. One only remain mystery: how the heck it worked previously... 😉 So yeah, topic closed.

View solution in original post

szymon_cwieka
Explorer

I just forgot to add service.Login("login", "password"); after Splunk.Service service = new Splunk.Service(connectArgs);
Stupid me. One only remain mystery: how the heck it worked previously... 😉 So yeah, topic closed.

Get Updates on the Splunk Community!

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...