Improve the C# API client

Depending on your Visual Studio version and the NuGet packages you receive with the client, you may face a few challenges when trying to build the C# client. The following unordered steps detail typical symptoms and solutions.

  • Update the project .NET version.

    Before you update the NuGet packages, first adjust the .NET Framework version of the project to a version that works with the latest packages, preferably .NET Framework 4.6.2 or later.

  • Update NuGet packages.

    After opening the IO.Swagger solution and trying to build the IO.Swagger library, you may see the following errors:
    Build errors

    In this case, you should update the NuGet packages.
    NUnit

    You need NUnit only for building IO.Swagger.Test, but not required for building IO.Swagger.
  • Fix code errors caused by package and .NET version conflicts.

    You may not need to update RestSharp in order to build IO.Swagger, but if you do, then you may see the following build error:
    Build error after RestSharp update

    1. Look for the problematic parameter of the AddFile method:
      Problematic code

    2. Add param.Value.ContentLength as a parameter:
      Fixed code

  • Consider which authentication scheme – if any – to use.

    If the client uses Windows Domain authentication, you should provide the proper credentials in the code, in the PrepareRequest function in ApiClient.cs. You may do any of the following:

    • Pass the credential of the current process by using the following code:

      request.UseDefaultCredentials = true;

    • Set a specific user with the valid UserName, Password and Domain:

      request.Credentials = new NetworkCredential(UserName, Password, Domain);

Once you fix all issues, you can build IO.Swagger and either replace the Library files in the .NET Samples collection or use them in your project.