Splunk Dev

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

niketn
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

niketn
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!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...