optimizely / csharp-sdk

.NET based C# SDK for Optimizely Feature Experimentation and Optimizely Full Stack (legacy)
https://docs.developers.optimizely.com/experimentation/v4.0.0-full-stack/docs/csharp-sdk
Apache License 2.0
19 stars 20 forks source link

Make optimizely compatible with newer version of NJsonSchema #284

Closed benspeth closed 2 years ago

benspeth commented 3 years ago

Hi,

I am using NJsonSchema v10.4.6 on my app (due to some new dependency added) and optimizely started throwing the following exception.

System.TypeLoadException: Could not load type 'NJsonSchema.JsonSchema4' from assembly 'NJsonSchema, Version=10.4.6.0, Culture=neutral, PublicKeyToken=c2f9c3bdfae56102'.
  ?, in bool Validator.ValidateJSONSchema(string configJson, string schemaJson)
  ?, in new Optimizely(string datafile, IEventDispatcher eventDispatcher, ILogger logger, IErrorHandler errorHandler, UserProfileService userProfileService, bool skipJsonValidation, EventProcessor eventProcessor)

Is it possible to make optimizely sdk compatible with newer version of NJsonSchema ?

dustin-sier commented 2 years ago

Hi @benspeth, we'll take a look and see what our options are.

benrobot commented 2 years ago

I'm having the same issue. The SDK was working fine until I started using NSwag and then Optimizely broke.

Workaround

Change from

var client = new Optimizely(dataFile);

To

var client = new Optimizely(dataFile, skipJsonValidation: true);

Root Cause

Looks like, starting with version 10.x, NJsonSchema introduced a breaking change.

Screenshot showing class name loses the number 4 starting with version 10.x
Screenshot showing class name loses the number 4 starting with version 10.x

Maybe the nuspec should look like this, note the ranges in the NJsonSchema dependencies

<?xml version="1.0" encoding="utf-8"?>
<package>
    <metadata>
        <id>Optimizely.SDK</id>
        <version>3.2.0</version>
        <title>Optimizely C# SDK</title>
        <authors>Optimizely Development Team</authors>
        <owners>fullstack.optimizely</owners>
        <license type="expression">Apache-2.0</license>
        <projectUrl>https://github.com/optimizely/csharp-sdk</projectUrl>
        <icon>OptimizelySDK.png</icon>
        <iconUrl>https://github.com/optimizely/csharp-sdk/blob/master/OptimizelySDK.png?raw=true</iconUrl>
        <requireLicenseAcceptance>false</requireLicenseAcceptance>
        <description>C# SDK for Optimizely X Fullstack</description>
        <releaseNotes>https://github.com/optimizely/csharp-sdk/blob/master/CHANGELOG.md</releaseNotes>
        <copyright>Copyright 2017-2019</copyright>
        <tags>Optimizely</tags>
        <dependencies>
            <group targetFramework=".NETFramework4.5">
                <dependency id="murmurhash-signed" version="1.0.2" />
                <dependency id="Newtonsoft.Json" version="9.0.1" />
                <dependency id="NJsonSchema" version="[8.30.6304.31883,10)" />
            </group>
            <group targetFramework=".NETFramework3.5">
                <dependency id="murmurhash-signed" version="1.0.2" />
                <dependency id="Newtonsoft.Json" version="9.0.1" />
            </group>
            <group targetFramework=".NETFramework4.0">
                <dependency id="murmurhash-signed" version="1.0.2" />
                <dependency id="Newtonsoft.Json" version="9.0.1" />
            </group>
            <group targetFramework=".NETStandard1.6">
                <dependency id="NETStandard.Library" version="1.6.1" />
                <dependency id="murmurhash-signed" version="1.0.2" />
                <dependency id="Newtonsoft.Json" version="9.0.1" />
                <dependency id="NJsonSchema" version="[8.33.6323.36213,10)" />
            </group>
            <group targetFramework="netstandard2.0">
                <dependency id="NETStandard.Library" version="2.0.3" />
                <dependency id="murmurhash-signed" version="1.0.2" />
                <dependency id="Newtonsoft.Json" version="9.0.1" />
                <dependency id="NJsonSchema" version="[8.33.6323.36213,10)" />
                <dependency id="System.Configuration.ConfigurationManager" version="4.5.0" />
            </group>
        </dependencies>
    </metadata>
    <files>
        <file src="./../OptimizelySDK.png" target="OptimizelySDK.png" />
        <file src="lib\**" target="lib" />
    </files>
</package>
dustin-sier commented 2 years ago

We're going to investigate our options for the nuspec definition. Thanks for the additional information.

msohailhussain commented 2 years ago

@[benspeth] For now, the workaround is to by-pass datafile json validation. In our next major release we will upgrade NJsonScheme to the newer one and nuspec file. Please close this issue if you agree or we can help you to build the nuget / DLL at your end and you can make the change yourself.

msohailhussain commented 2 years ago

Closing this ticket. Feel free to contact if you need more details.