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 (in Linux/Mono with .net 4.8)

See original GitHub issue

Logs and network traces This is the log of what I’m getting:

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

Which version of MSAL.NET are you using? Not exactly sure. I was using Azure.Security.KeyVault.Secrets 4.3.0 which internally uses MSAL

Platform .NET 4.8 Mono/Ubuntu 18.4

What authentication flow has the issue?

  • Desktop / Mobile
    • Interactive
    • Integrated Windows Authentication
    • Username Password
    • Device code flow (browserless)
  • Web app
    • Authorization code
    • On-Behalf-Of
  • Daemon app
    • Service to Service calls

Is this a new or existing app? New app

Repro 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 it always failed with the error above

Using Mono because the feature will be implemented in a .Net 4.8 application and the unit/integration tests will be executed from an Ubuntu machine. Same tutorial above in a .net core (still in Ubuntu) worked without any issues.

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

Expected behavior Program should authenticate and retrieve the secret

Actual behavior Program crashes when is trying to log (the MSAL library) something and it’s trying to figure out the OS

Additional context / logs / screenshots / links to code Originally posted this in the Azure SDK project and they redirect me to this project. This is the issue I created there: https://github.com/Azure/azure-sdk-for-net/issues/26368

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
ngcdevcommented, Feb 7, 2022

Hi @bgavrilMS Thanks for your response. Yes, I understand about Mono. Fortunately, I was able to make the code change with .Net Core and that worked perfectly. So for me this is not an emergency, just something that you could consider fixing if you have time. This is the code I used, which is basically the sample in the documentation about using Azure Secrets:

using System;
using Azure.Security.KeyVault.Secrets;
using Azure.Identity;
using System.Threading.Tasks;

namespace TestSecrets
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			MainRun().GetAwaiter().GetResult();
		}

		public static async Task MainRun()
		{
			string keyVaultUrl = "https://<account here>.vault.azure.net/";

			// Using DeafultAzureCredentials with env vars for:
			// AZURE_CLIENT_ID, AZURE_TENANT_ID and AZURE_CLIENT_SECRET 
			var client = new SecretClient(new Uri(keyVaultUrl), new DefaultAzureCredential());

			var kvresult = await client.GetSecretAsync("abc-secret");

			Console.WriteLine(kvresult.Value);
		}
	}
}

Thank you!

0reactions
bgavrilMScommented, Dec 21, 2022

Won’t fix. Please use .NET

Read more comments on GitHub >

github_iconTop Results From Across the Web

GetWindowsVersionStringInternal Object reference not set ...
I'm pasting the exact code that I'm using below. Notice: I'm running under Ubuntu, using Mono and .Net Framework 4.8. It seems like...
Read more >
"Object reference not set to an instance of an ...
I have an application written in asp.net core 7.0 that working fine on local (using Windows to develop). But when I deploy it...
Read more >
Azure Identity client library for .NET
The Azure Identity library provides Azure Active Directory (Azure AD) token authentication support across the Azure SDK. It provides a set of ...
Read more >
Azure function failing with “Object reference not set to an ...
Azure function failing with “Object reference not set to an instance of an object”. I have an Azure application that uses an Office...
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