GetConfigurationOrDefault throwing Object reference not set to an instance of an object

I’m upgrading from using Okta Sdk 5.x to 8.x (C#). Attempting to replace the old client with the new API structure. Starting with the basics I’ve tried to run the code https_github_com/okta/okta-sdk-dotnet/blob/master/docs/UserApi.md#getuser , not replacing any of the configuration values just trying to get a UserApi object created. I consistently get “Object reference not set to an instance of an object.” Even if I replace the values in the example I get the same. I do not have a appsettings.json nor a okta.yaml file as we don’t store configuration in static files.

The stacktrace is

> Microsoft.Extensions.Configuration.Binder.dll!Microsoft.Extensions.Configuration.ConfigurationBinder.GetAllProperties(System.Type type) Line 462 C#
Microsoft.Extensions.Configuration.Binder.dll!Microsoft.Extensions.Configuration.ConfigurationBinder.BindNonScalar(Microsoft.Extensions.Configuration.IConfiguration configuration, object instance, Microsoft.Extensions.Configuration.BinderOptions options) Line 125 C#
Microsoft.Extensions.Configuration.Binder.dll!Microsoft.Extensions.Configuration.ConfigurationBinder.BindInstance(System.Type type, object instance, Microsoft.Extensions.Configuration.IConfiguration config, Microsoft.Extensions.Configuration.BinderOptions options) Line 272 C#
Microsoft.Extensions.Configuration.Binder.dll!Microsoft.Extensions.Configuration.ConfigurationBinder.BindDictionary(object dictionary, System.Type dictionaryType, Microsoft.Extensions.Configuration.IConfiguration config, Microsoft.Extensions.Configuration.BinderOptions options) Line 316 C#
Microsoft.Extensions.Configuration.Binder.dll!Microsoft.Extensions.Configuration.ConfigurationBinder.AttemptBindToCollectionInterfaces(System.Type type, Microsoft.Extensions.Configuration.IConfiguration config, Microsoft.Extensions.Configuration.BinderOptions options) Line 195 C#
Microsoft.Extensions.Configuration.Binder.dll!Microsoft.Extensions.Configuration.ConfigurationBinder.BindInstance(System.Type type, object instance, Microsoft.Extensions.Configuration.IConfiguration config, Microsoft.Extensions.Configuration.BinderOptions options) Line 243 C#
Microsoft.Extensions.Configuration.Binder.dll!Microsoft.Extensions.Configuration.ConfigurationBinder.BindCollection(object collection, System.Type collectionType, Microsoft.Extensions.Configuration.IConfiguration config, Microsoft.Extensions.Configuration.BinderOptions options) Line 342 C#
Microsoft.Extensions.Configuration.Binder.dll!Microsoft.Extensions.Configuration.ConfigurationBinder.BindInstance(System.Type type, object instance, Microsoft.Extensions.Configuration.IConfiguration config, Microsoft.Extensions.Configuration.BinderOptions options) Line 264 C#
Microsoft.Extensions.Configuration.Binder.dll!Microsoft.Extensions.Configuration.ConfigurationBinder.BindProperty(System.Reflection.PropertyInfo property, object instance, Microsoft.Extensions.Configuration.IConfiguration config, Microsoft.Extensions.Configuration.BinderOptions options) Line 158 C#
Microsoft.Extensions.Configuration.Binder.dll!Microsoft.Extensions.Configuration.ConfigurationBinder.BindNonScalar(Microsoft.Extensions.Configuration.IConfiguration configuration, object instance, Microsoft.Extensions.Configuration.BinderOptions options) Line 143 C#
Microsoft.Extensions.Configuration.Binder.dll!Microsoft.Extensions.Configuration.ConfigurationBinder.BindInstance(System.Type type, object instance, Microsoft.Extensions.Configuration.IConfiguration config, Microsoft.Extensions.Configuration.BinderOptions options) Line 272 C#
Microsoft.Extensions.Configuration.Binder.dll!Microsoft.Extensions.Configuration.ConfigurationBinder.Bind(Microsoft.Extensions.Configuration.IConfiguration configuration, object instance, System.Action<Microsoft.Extensions.Configuration.BinderOptions> configureOptions) Line 90 C#
Okta.Sdk.dll!Okta.Sdk.Client.Configuration.GetConfigurationOrDefault(Okta.Sdk.Client.Configuration configuration) Line 856 C#
Okta.Sdk.dll!Okta.Sdk.Api.UserApi.UserApi(Okta.Sdk.Client.Configuration configuration, Okta.Sdk.Client.IOAuthTokenProvider oAuthTokenProvider, System.Net.WebProxy webProxy) Line 1032 C#

Code Block

            Configuration config = new Configuration();
            config.OktaDomain = "https://subdomain.okta.com";
            // Configure API key authorization: apiToken
            config.Token ="YOUR_API_KEY";
            // Configure OAuth2 access token for authorization: oauth2
            config.AccessToken = "YOUR_ACCESS_TOKEN";

            var apiInstance = new UserApi(config);
            var userId = "userId_example";  // string | 

            try
            {
                // Retrieve a User
                User result = apiInstance.GetUser(userId);
                Debug.WriteLine(result);
            }
            catch (ApiException  e)
            {
                Debug.Print("Exception when calling UserApi.GetUser: " + e.Message );
                Debug.Print("Status Code: "+ e.ErrorCode);
                Debug.Print(e.StackTrace);
            }

Hello there,

My name is Akash, and I will be handling this issue.

Could you please specify the exact version of the SDK in which you are facing the error?

I started with 8.0.0, and then 8.0.1 was released, and I’ve tried that as well.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.