Developing for Splunk Platform

Easiest way to access Splunk API from VS 2017

stufty
Path Finder

environment:
Windows 10, VS pro 2017 v 15.3.3,
Create a console application,
using nuget, I installed Splunk.Client v 2.2.0, which required System.Collections.Immutable v1.3.1
edit Program.c to have this:

    static void Main(string[] args)
    { Read(); }

    private static async void Read()
    {
        Service splunkService = await GetCloudService();
        Job job = await splunkService.Jobs.CreateAsync("search index=* | head 10");
        using (SearchResultStream stream = await job.GetSearchResultsAsync())
        { }
    }

    private static async Task<Service> GetCloudService()
    {
        Service splunkService = new Service(new Uri("https://localhost:8089"));
        await splunkService.LogOnAsync("admin", "changeme");
        return splunkService;
    }

It complies, but it does not run, gets this error:

Description: An assembly (probably "Splunk.CLient") must be rewritten using the code contracts binary rewriter (CCRewrite) because it is calling Contract.Requires and the CONTRACTS_FULL symbol is defined.Remove any explicit definitions of the CONTRACTS_FULL symbol from your project and rebuild.

Do I really have to rebuild Splunk.Client? Is there another package I should be using? Any help will be greatly appreciated. I also tried with Splunk Client v2.2.7 and immutable v1.4.0 with the same results.

I tried to tag with Splunk.Client to no avail.

Thanks - Steve

Tags (2)
1 Solution

stufty
Path Finder

I have posted working C# dlls to my GitHub page. URL: https://github.com/poparosa/Splunk.Client

View solution in original post

stufty
Path Finder

I have posted working C# dlls to my GitHub page. URL: https://github.com/poparosa/Splunk.Client

niketnilay
Legend

@stuffy, thanks for uploading a long time due fix for this issue. Can you add the link to your GitHub repository and accept your own answer to mark this question as answered and help several others who are facing the same issue?

I would also check and confirm as soon as I can! Thanks again!

https://github.com/splunk/splunk-sdk-csharp-pcl/issues/42

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

stufty
Path Finder

Hi niketnilay,

I posted my GitHub link to the bottom of the link you just supplied. I tried posting my GitHub link here, but apparently, I do not have the chops required to post a link to the answers. Perhaps I can post now to a comment - here goes:

https://github.com/poparosa/Splunk.Client

Thanks - Steve

0 Karma

niketnilay
Legend

@stufty, can you check out the following thread?

https://github.com/splunk/splunk-sdk-csharp-pcl/issues/42

Either try with Splunk Client 2.2.5 or check the latest updates in the thread.

If the issue is not resolved, I would recommend adding as much details to reproduce as possible.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

stufty
Path Finder

To Reproduce:

*) Open Visual studio (2017 or 2015)
*) Create a new console application,
*) Using nuget manager, install Splunk.Client v 2.2.0, which requires System.Collections.Immutable v1.3.1
*) Edit Program.c to have the code above.:
*) Add #include Splunk.Client to Program.c at the top of the file
*) Build (this works OK)
*) Debug --> this dies before first instruction is executed

Thanks - Steve

0 Karma

stufty
Path Finder

Hello niketnilay,

Thanks for the quick response.

I have tried Splunk.Client v2.2.5 as you suggested with no luck
I have also tried v2.2.7 with no success.

I have also tried Visual Studio 2015, as the Code Contracts could not be found on VS 2017.

The link you mention is for VS2015 and talks about checking the "Perform Runtime Contract Checking", and when I tried that the project would not build, as I got this error (even running as administrator):
The command ""C:\Program Files (x86)\Microsoft\Contracts\Bin\ccrewrite.exe" "@SplunkCLientccrewrite.rsp"" exited with code -1. SplunkCLient

What version of Visual Studio and Splunk.Client should I be using?

0 Karma
Get Updates on the Splunk Community!

Improve Your Security Posture

Watch NowImprove Your Security PostureCustomers are at the center of everything we do at Splunk and security ...

Maximize the Value from Microsoft Defender with Splunk

 Watch NowJoin Splunk and Sens Consulting for this Security Edition Tech TalkWho should attend:  Security ...

This Week's Community Digest - Splunk Community Happenings [6.27.22]

Get the latest news and updates from the Splunk Community here! News From Splunk Answers ✍️ Splunk Answers is ...