keenlabs / keen-sdk-net

A .NET SDK for the Keen IO API
MIT License
37 stars 23 forks source link

.NET 3.5 version of SDK fails during runtime #38

Closed baumatron closed 7 years ago

baumatron commented 7 years ago

The nuget KeenClient package installed for a project that targets .NET 3.5 will fail at runtime when trying to load Netwonsoft.Json.dll.

Repo steps:

  1. Open Visual Studio 2015 Community Edition Update 3
  2. Create a new C# console application (File->New->Project..., select .NET Framework 3.5, Visual C#->Console Application)
  3. Open nuget package manager console and run PM> Install-Package KeenClient
  4. Paste the following code into Program.cs and add a valid project and write key:
    
    using Keen.NET_35;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

namespace keen_35_test_console { class Program { static void Main(string[] args) { var projectId = ""; var writeKey = "";

        var project = new ProjectSettingsProvider(
            projectId,
            writeKey: writeKey
            );

        var client = new KeenClient(project);

        var collection = "test_collection";
        client.AddEvent(collection, new { string_key = "3.5", numeric_key = 7.123 });
    }
}

}


5. Run the program

Expected:
6. Event is added to the "test_collection" collection.

Actual:
6. Program crashes with a System.IO.FileLoadException.

Exception details:
An unhandled exception of type 'System.IO.FileLoadException' occurred in keen_35_test_console.exe

Additional information: Could not load file or assembly 'Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Perhaps this is because there are version conflicts in the version of Newtonsoft.Json being referenced. The root KeenClient.nuspec references version 6.0.3 of Newtonsoft.json, while Keen.NET_35.csproj references ..\packages\Netwonsoft.Json.8.0.3\lib\net35\Netwonsoft.Json.dll. Keen.NET_35/packages.config also references version 8.0.3 of the library. If I manually install version 8.0.3 instead of version 6.0.3, the program runs as expected. So the solution seems to be reference version 8.0.3 in KeenClient.nuspec for target "net35".
masojus commented 7 years ago

It might not be a bad idea to update to 9.0.1 while we're at it, assuming it's not a breaking change.

masojus commented 7 years ago

Fixed by Pull Request #44