okta / okta-sdk-dotnet

A .NET SDK for interacting with the Okta management API, enabling server-side code to manage Okta users, groups, applications, and more.
Other
160 stars 100 forks source link

Unable to instanciate OktaClient with .NET Standard 2.0 #515

Closed christophecolly closed 2 years ago

christophecolly commented 3 years ago

Hi,

I'm using version 5.2.1 of the Okta.Sdk and trying to instantiate a client in a .NET Standard 2.0 console app:

using System;
using Okta.Sdk;
using Okta.Sdk.Configuration;

namespace OktaSdk1
{
    internal class Program
    {
        static void Main(string[] args)
        {
            var client = new OktaClient(new OktaClientConfiguration
            {
                OktaDomain = "https://domain.okta.com",
                Token = "myApiToken"
            });
        }
    }
}

.csproj project file:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netstandard2.0</TargetFramework>

    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>

  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Okta.Sdk" Version="5.2.1" />
  </ItemGroup>

</Project>

I get the following error when trying to debug:

Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=12.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)
   at Okta.Sdk.Abstractions.Configuration.Providers.Object.ObjectExtension.AddObject(IConfigurationBuilder builder, Object object, String root)
   at Okta.Sdk.OktaClient.GetConfigurationOrDefault(OktaClientConfiguration apiClientConfiguration)
   at Okta.Sdk.OktaClient..ctor(OktaClientConfiguration apiClientConfiguration, ILogger logger, ISerializer serializer)
   at OktaSdk1.Program.Main(String[] args) in C:\Users\user\source\repos\OktaSdk\OktaSdk\Program.cs:line 11

If I change Okta.Sdk version to 5.2.0 it works. If I change to .NET 5 instead of .NET Standard 2.0 it works.

Any help would be much appreciated.

andriizhegurov-okta commented 3 years ago

Hi @christophecolly, thank you for reporting the issue. I apologize for the inconvenience. We will investigate it internally and update you here. Please use Okta.Sdk version 5.2.0 meanwhile. Version 5.2.1 uses different configuration dependencies but in terms of functionality, 5.2.0 and 5.2.1 are the same.

christophecolly commented 3 years ago

Thanks for your feedback, I will use 5.2.0 for now.

Christian-Oleson commented 3 years ago

Thanks for your feedback, I will use 5.2.0 for now.

@christophecolly , Did that actually fix your issue? I have a similar issue and the downgrade did not fix it for me.

christophecolly commented 3 years ago

@Christian-Oleson Yes I can confirm that downgrading to 5.2.0 fixes the issue for me. Are you also targeting .NET Standard 2.0?

Christian-Oleson commented 3 years ago

@Christian-Oleson Yes I can confirm that downgrading to 5.2.0 fixes the issue for me. Are you also targeting .NET Standard 2.0?

I'm not, I'm targeting .NET 5.

christophecolly commented 3 years ago

For me it works as expected with .NET 5 and SDK 5.2.1.

Christian-Oleson commented 3 years ago

For me it works as expected with .NET 5 and SDK 5.2.1.

Thank you for confirming!

93ramadan commented 2 years ago

Hello I am using .net core 3.1 and facing this issue - what’s the recommended fix please (besides upgrading to .net 5)? Much appreciate

andriizhegurov-okta commented 2 years ago

This should be fixed in Okta.Sdk v5.3.2