question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GetWindowsVersionStringInternal Object reference not set to an instance of an object

See original GitHub issue

Hello,

I was following the instructions here https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/README.md to use Azure Key Vault in my program, particularly using the “Service Principal with Secret”. I got everything setup (registered the app, got a secret, granted access in key vault to the app, setup the environment variables), but when I run my code:

string keyVaultUrl = ".... key vault URL here ...";
var client = new SecretClient(new Uri(keyVaultUrl), new DefaultAzureCredential());
var kvresult = await Client.GetSecretAsync("secretname");

I get the following error (I’m running under Ubuntu with Mono and using .NET Framework 4.8 in my project, because that’s the version of the system where I need to implement this):

Azure.Identity.AuthenticationFailedException: ClientSecretCredential authentication failed: Object reference not set to an instance of an object ---> System.NullReferenceException: Object reference not set to an instance of an object
  at Microsoft.Identity.Client.Platforms.Features.DesktopOs.DesktopOsHelper.GetWindowsVersionStringInternal () [0x0000f] in <bf76092abc204c3b87b8ffb18ff15aa1>:0 
  at Microsoft.Identity.Client.Platforms.Features.DesktopOs.DesktopOsHelper+<>c.<.cctor>b__16_2 () [0x00000] in <bf76092abc204c3b87b8ffb18ff15aa1>:0 
  at System.Lazy`1[T].ViaFactory (System.Threading.LazyThreadSafetyMode mode) [0x00043] in <533173d24dae460899d2b10975534bb0>:0 
  at System.Lazy`1[T].ExecutionAndPublication (System.LazyHelper executionAndPublication, System.Boolean useDefaultConstructor) [0x00022] in <533173d24dae460899d2b10975534bb0>:0 
  at System.Lazy`1[T].CreateValue () [0x00074] in <533173d24dae460899d2b10975534bb0>:0 
  at System.Lazy`1[T].get_Value () [0x0000a] in <533173d24dae460899d2b10975534bb0>:0 
  at Microsoft.Identity.Client.Platforms.Features.DesktopOs.DesktopOsHelper.GetWindowsVersionString () [0x00000] in <bf76092abc204c3b87b8ffb18ff15aa1>:0 
  at Microsoft.Identity.Client.Platforms.net45.NetDesktopPlatformProxy.InternalGetOperatingSystem () [0x00000] in <bf76092abc204c3b87b8ffb18ff15aa1>:0 
  at System.Lazy`1[T].ViaFactory (System.Threading.LazyThreadSafetyMode mode) [0x00043] in <533173d24dae460899d2b10975534bb0>:0 
  at System.Lazy`1[T].ExecutionAndPublication (System.LazyHelper executionAndPublication, System.Boolean useDefaultConstructor) [0x00022] in <533173d24dae460899d2b10975534bb0>:0 
  at System.Lazy`1[T].CreateValue () [0x00074] in <533173d24dae460899d2b10975534bb0>:0 
  at System.Lazy`1[T].get_Value () [0x0000a] in <533173d24dae460899d2b10975534bb0>:0 
  at Microsoft.Identity.Client.PlatformsCommon.Shared.AbstractPlatformProxy.GetOperatingSystem () [0x00000] in <bf76092abc204c3b87b8ffb18ff15aa1>:0 
  at Microsoft.Identity.Client.Internal.MsalIdHelper.GetMsalIdParameters (Microsoft.Identity.Client.Core.ICoreLogger logger) [0x00057] in <bf76092abc204c3b87b8ffb18ff15aa1>:0 
  at Microsoft.Identity.Client.Internal.Logger.MsalLogger+<>c.<.cctor>b__44_2 () [0x00000] in <bf76092abc204c3b87b8ffb18ff15aa1>:0 
  at System.Lazy`1[T].ViaFactory (System.Threading.LazyThreadSafetyMode mode) [0x00043] in <533173d24dae460899d2b10975534bb0>:0 
  at System.Lazy`1[T].ExecutionAndPublication (System.LazyHelper executionAndPublication, System.Boolean useDefaultConstructor) [0x00022] in <533173d24dae460899d2b10975534bb0>:0 
  at System.Lazy`1[T].CreateValue () [0x00074] in <533173d24dae460899d2b10975534bb0>:0 
  at System.Lazy`1[T].get_Value () [0x0000a] in <533173d24dae460899d2b10975534bb0>:0 
  at Microsoft.Identity.Client.Internal.Logger.MsalLogger.Log (Microsoft.Identity.Client.LogLevel logLevel, System.String messageWithPii, System.String messageScrubbed) [0x00057] in <bf76092abc204c3b87b8ffb18ff15aa1>:0 
  at Microsoft.Identity.Client.Internal.Logger.MsalLogger.Info (System.String messageScrubbed) [0x00000] in <bf76092abc204c3b87b8ffb18ff15aa1>:0 
  at Microsoft.Identity.Client.ApiConfig.Executors.AbstractExecutor.CreateRequestContextAndLogVersionInfo (System.Guid correlationId, System.Threading.CancellationToken userCancellationToken) [0x00043] in <bf76092abc204c3b87b8ffb18ff15aa1>:0 
  at Microsoft.Identity.Client.ApiConfig.Executors.ConfidentialClientExecutor.ExecuteAsync (Microsoft.Identity.Client.ApiConfig.Parameters.AcquireTokenCommonParameters commonParameters, Microsoft.Identity.Client.ApiConfig.Parameters.AcquireTokenForClientParameters clientParameters, System.Threading.CancellationToken cancellationToken) [0x00020] in <bf76092abc204c3b87b8ffb18ff15aa1>:0 
  at Azure.Identity.AbstractAcquireTokenParameterBuilderExtensions.ExecuteAsync[T] (Microsoft.Identity.Client.AbstractAcquireTokenParameterBuilder`1[T] builder, System.Boolean async, System.Threading.CancellationToken cancellationToken) [0x00078] in <b1ff7d3abac2485b914a6579d21f78c2>:0 
  at Azure.Identity.MsalConfidentialClient.AcquireTokenForClientAsync (System.String[] scopes, System.String tenantId, System.Boolean async, System.Threading.CancellationToken cancellationToken) [0x00140] in <b1ff7d3abac2485b914a6579d21f78c2>:0 
  at Azure.Identity.ClientSecretCredential.GetTokenAsync (Azure.Core.TokenRequestContext requestContext, System.Threading.CancellationToken cancellationToken) [0x000c3] in <b1ff7d3abac2485b914a6579d21f78c2>:0 
   --- End of inner exception stack trace ---
  at Azure.Identity.CredentialDiagnosticScope.FailWrapAndThrow (System.Exception ex, System.String additionalMessage) [0x0001d] in <b1ff7d3abac2485b914a6579d21f78c2>:0 
  at Azure.Identity.ClientSecretCredential.GetTokenAsync (Azure.Core.TokenRequestContext requestContext, System.Threading.CancellationToken cancellationToken) [0x000ef] in <b1ff7d3abac2485b914a6579d21f78c2>:0 
  at Azure.Identity.EnvironmentCredential.GetTokenImplAsync (System.Boolean async, Azure.Core.TokenRequestContext requestContext, System.Threading.CancellationToken cancellationToken) [0x000d5] in <b1ff7d3abac2485b914a6579d21f78c2>:0 
  at Azure.Identity.CredentialDiagnosticScope.FailWrapAndThrow (System.Exception ex, System.String additionalMessage) [0x00018] in <b1ff7d3abac2485b914a6579d21f78c2>:0 
  at Azure.Identity.EnvironmentCredential.GetTokenImplAsync (System.Boolean async, Azure.Core.TokenRequestContext requestContext, System.Threading.CancellationToken cancellationToken) [0x0010d] in <b1ff7d3abac2485b914a6579d21f78c2>:0 
  at Azure.Identity.EnvironmentCredential.GetTokenAsync (Azure.Core.TokenRequestContext requestContext, System.Threading.CancellationToken cancellationToken) [0x0007d] in <b1ff7d3abac2485b914a6579d21f78c2>:0 
  at Azure.Identity.DefaultAzureCredential.GetTokenFromSourcesAsync (Azure.Core.TokenCredential[] sources, Azure.Core.TokenRequestContext requestContext, System.Boolean async, System.Threading.CancellationToken cancellationToken) [0x000aa] in <b1ff7d3abac2485b914a6579d21f78c2>:0 
  at Azure.Identity.DefaultAzureCredential.GetTokenImplAsync (System.Boolean async, Azure.Core.TokenRequestContext requestContext, System.Threading.CancellationToken cancellationToken) [0x001ed] in <b1ff7d3abac2485b914a6579d21f78c2>:0 
  at Azure.Identity.CredentialDiagnosticScope.FailWrapAndThrow (System.Exception ex, System.String additionalMessage) [0x00018] in <b1ff7d3abac2485b914a6579d21f78c2>:0 
  at Azure.Identity.DefaultAzureCredential.GetTokenImplAsync (System.Boolean async, Azure.Core.TokenRequestContext requestContext, System.Threading.CancellationToken cancellationToken) [0x00253] in <b1ff7d3abac2485b914a6579d21f78c2>:0 
  at Azure.Identity.DefaultAzureCredential.GetTokenAsync (Azure.Core.TokenRequestContext requestContext, System.Threading.CancellationToken cancellationToken) [0x0007d] in <b1ff7d3abac2485b914a6579d21f78c2>:0 
  at Azure.Core.Pipeline.BearerTokenAuthenticationPolicy+AccessTokenCache.GetHeaderValueFromCredentialAsync (Azure.Core.TokenRequestContext context, System.Boolean async, System.Threading.CancellationToken cancellationToken) [0x00092] in <056f6eea93f94d71966248c0a1937819>:0 
  at Azure.Core.Pipeline.BearerTokenAuthenticationPolicy+AccessTokenCache.GetHeaderValueAsync (Azure.Core.HttpMessage message, Azure.Core.TokenRequestContext context, System.Boolean async) [0x0024f] in <056f6eea93f94d71966248c0a1937819>:0 
  at Azure.Core.Pipeline.BearerTokenAuthenticationPolicy+AccessTokenCache.GetHeaderValueAsync (Azure.Core.HttpMessage message, Azure.Core.TokenRequestContext context, System.Boolean async) [0x003d0] in <056f6eea93f94d71966248c0a1937819>:0 
  at Azure.Core.Pipeline.BearerTokenAuthenticationPolicy.AuthenticateAndAuthorizeRequestAsync (Azure.Core.HttpMessage message, Azure.Core.TokenRequestContext context) [0x00082] in <056f6eea93f94d71966248c0a1937819>:0 
  at Azure.Security.KeyVault.ChallengeBasedAuthenticationPolicy.AuthorizeRequestOnChallengeAsyncInternal (Azure.Core.HttpMessage message, System.Boolean async) [0x0018b] in <cf13f41e36fd4a94b87ece865a0bbfd5>:0 
  at Azure.Core.Pipeline.BearerTokenAuthenticationPolicy.ProcessAsync (Azure.Core.HttpMessage message, System.ReadOnlyMemory`1[T] pipeline, System.Boolean async) [0x0020e] in <056f6eea93f94d71966248c0a1937819>:0 
  at Azure.Core.Pipeline.RedirectPolicy.ProcessAsync (Azure.Core.HttpMessage message, System.ReadOnlyMemory`1[T] pipeline, System.Boolean async) [0x00090] in <056f6eea93f94d71966248c0a1937819>:0 
  at Azure.Core.Pipeline.RetryPolicy.ProcessAsync (Azure.Core.HttpMessage message, System.ReadOnlyMemory`1[T] pipeline, System.Boolean async) [0x000b4] in <056f6eea93f94d71966248c0a1937819>:0 
  at Azure.Core.Pipeline.RetryPolicy.ProcessAsync (Azure.Core.HttpMessage message, System.ReadOnlyMemory`1[T] pipeline, System.Boolean async) [0x00193] in <056f6eea93f94d71966248c0a1937819>:0 
  at Azure.Core.Pipeline.HttpPipeline.SendRequestAsync (Azure.Core.Request request, System.Threading.CancellationToken cancellationToken) [0x00093] in <056f6eea93f94d71966248c0a1937819>:0 
  at Azure.Security.KeyVault.KeyVaultPipeline.SendRequestAsync (Azure.Core.Request request, System.Threading.CancellationToken cancellationToken) [0x0008e] in <cf13f41e36fd4a94b87ece865a0bbfd5>:0 
  at Azure.Security.KeyVault.KeyVaultPipeline.SendRequestAsync[TResult] (Azure.Core.RequestMethod method, System.Func`1[TResult] resultFactory, System.Threading.CancellationToken cancellationToken, System.String[] path) [0x0009a] in <cf13f41e36fd4a94b87ece865a0bbfd5>:0 
  at Azure.Security.KeyVault.Secrets.SecretClient.GetSecretAsync (System.String name, System.String version, System.Threading.CancellationToken cancellationToken) [0x00131] in <cf13f41e36fd4a94b87ece865a0bbfd5>:0

Any help will be appreciated. Thanks!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ngcdevcommented, Jan 21, 2022

Final comment: Did the integration test in .Net Core (5.0) and everything worked fine from an Ubuntu machine. Thanks for the quick responses!

1reaction
christothescommented, Jan 21, 2022

@ngcdev would you mind creating an issue for this over in the MSAL repo here?:

https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use MSAL to retrieve authorization token on Mono for MacOS
NullReferenceException : Object reference not set to an instance of an object at Microsoft.Identity.Client.PlatformsCommon.Shared.
Read more >
How to solve error object reference not set to an instance of ...
I work on csharp i get error object reference not set to an instance of an object code give me error var Data...
Read more >
Fix “Object Reference Not Set to an Instance of an ... - YouTube
Fix “ Object Reference Not Set to an Instance of an Object ” in Microsoft Visual Studio In this post, we will show...
Read more >
`Object reference not set to an instance of an ...
Scenario: How to use the Queue trigger to get the message from the queue and add that message details to the entity of...
Read more >
Object reference not set to an instance of an object.
While running on iOS 12.2 on an iPhone XR using Unity 2018.3.11 (IL2CPP) with PlayFab SDK 2.63.190312 using the following code: var request...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found