Splunk Dev

XmlException: Unexpected DTD declaration. Line 1, position 3.

jianzgao
Observer

When I try to use below code to test the API search:

 

 

var context = new Context(Scheme.Https, "www.splunk.com", 443);
using (var service = new Service(context, new Namespace(user: "nobody", app: "search")))
{
    Run(service).Wait();
}

/// <summary>
/// Called when [search].
/// </summary>
/// <param name="service">The service.</param>
/// <returns></returns>
static async Task Run(Service service)
{
    await service.LogOnAsync("aaa", "bbb");

    //// Simple oneshot search
    using (SearchResultStream stream = await service.SearchOneShotAsync("search index=test_index | head 5"))
    {
        foreach (SearchResult result in stream)
        {
            Console.WriteLine(result);
        }
    }
}

 

 

But failed, get the error message:
XmlException: Unexpected DTD declaration. Line 1, position 3.

Question:
int this line: new Namespace(user: "nobody", app: "search")
how to define the "user" and "app" parameters value?

I try to use this way:
var service = new Service(new Uri("https://www.splunk.com"));
but still failed and got the same error message.

 

0 Karma

VatsalJagani
SplunkTrust
SplunkTrust

@jianzgao - I think you are using C# SDK for Splunk.

Splunk has made that SDK deprecated - https://github.com/splunk/splunk-sdk-csharp-pcl

I would recommend using either Python SDK (https://github.com/splunk/splunk-sdk-python ) or Java SDK (https://github.com/splunk/splunk-sdk-java ) or Javascript SDK (https://github.com/splunk/splunk-sdk-javascript )

 

I hope this helps!!!

0 Karma

jianzgao
Observer

@VatsalJagani Thank you for your quick reply.

But as a .net platform soft engine, I would like perfer to use the C# SDK. I feel so confuse why deprecate the C# SDK. 
We plan to use C# SDK of splunk to implement some new features. 
Seem like we have to change the solution. 

Thank you again. 

0 Karma

VatsalJagani
SplunkTrust
SplunkTrust

@jianzgao - If you are just starting to work on a new solution, I won't recommend using C# as its been no changes to that for a long time. So you would have to end-up maintaining the library yourself, fixing all the issues similar to this one.

I have personally used Python SDK and its most widely used one if you are comfortable using it.

 

I hope this helps!!! Kindly upvote if this helps you!!!

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Monitoring AI Agents with Splunk Observability Cloud

Let’s say I’m running a travel planning AI app in production. A user asks for three concise hotel options in ...

[Puzzles] Solve, Learn, Repeat: Tiling

This puzzle (first published here) is based on finding groups of tessellated tiles (inspired by floor tiles I ...

SOK it to Me: Top 3 Benefits of Using Splunk Operator on Kubernetes that’ll Make ...

    Thursday, July 9, 2026  |  11:00AM–12:00PM PDT Duration: 1 hour (includes Q&A) Managing can feel like a ...