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.

[BUG] AzureServiceTokenProvider.GetAccessTokenAsync no longer works with Visual Studio 16.3

See original GitHub issue

Describe the bug

I work on a project that uses Azure Managed Identities. AzureServiceTokenProvider.GetAccessTokenAsync() is used to get a token, and to debug locally a token provided by Visual Studio is used. After upgrading to Visual Studio 16.3 this no longer works. I have verified this to be the case on two different computers after upgrading to Visual Studio 16.3.

I don’t know if this is a problem with Visual Studio or the NuGet package but the exception is thrown by the NuGet package so I’m reporting it here.

Exception or Stack Trace

Parameters: Connection String: RunAs=Developer; DeveloperTool=VisualStudio, Resource: https://management.azure.com, Authority: . Exception Message: Tried to get token using Visual Studio. Access token could not be acquired. Exception for Visual Studio token provider Microsoft.Asal.TokenService.exe : Token response is not in the expected format. Exception Message: There was an error deserializing the object of type Microsoft.Azure.Services.AppAuthentication.TokenResponse. Encountered unexpected character ‘D’.

   at Microsoft.Azure.Services.AppAuthentication.AzureServiceTokenProvider.<GetAuthResultAsyncImpl>d__14.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Microsoft.Azure.Services.AppAuthentication.AzureServiceTokenProvider.<GetAuthenticationResultAsync>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Microsoft.Azure.Services.AppAuthentication.AzureServiceTokenProvider.<GetAccessTokenAsync>d__16.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at UserQuery.<RunUserAuthoredQuery>d__0.MoveNext()

To Reproduce

Use Visual Studio 16.3 and configure an Azure account in Tools > Options > Azure Service Authentication > Account Selection.

Create a new instance of AzureServiceTokenProvider with connection string "RunAs=Developer; DeveloperTool=VisualStudio" and then call GetAccessTokenAsync("https://management.azure.com") to get a token.

Code Snippet

var connectionString = "RunAs=Developer; DeveloperTool=VisualStudio";
var azureServiceTokenProvider = new AzureServiceTokenProvider(connectionString);
var token = await azureServiceTokenProvider.GetAccessTokenAsync("https://management.azure.com");

Expected behavior

GetAccessTokenAsync should return a token that can be used to authenticate with Azure based on the configured account in Visual Studio and not throw an exception.

Screenshots

Azure Service Authentication

Setup (please complete the following information):

  • OS: Windows 10 Pro 1903 18362.356
  • IDE: Visual Studio 16.3.0
  • Version of the Library used: Microsoft.Azure.Services.AppAuthentication 1.3.1

Additional context

None.

Information Checklist

Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

  • Bug Description Added
  • Repro Steps Added
  • Setup information Added

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:21 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
vlardncommented, Dec 9, 2019

For me, the problem appeared after upgrading to Visual Studio 2019 16.4.0 from the previous version. I’ve found that this was caused by invalid TokenProvider path, so I was forced to change content of “%LOCALAPPDATA%.IdentityService\AzureServiceAuth\tokenprovider.json” file:

{ "TokenProviders": [ { "Path": "c:\\program files (x86)\\microsoft visual studio\\2019\\enterprise\\common7\\ide\\extensions\\1rzmhu0l.2xx\\TokenService\\Microsoft.Asal.TokenService.exe", "Arguments": [ "--serviceHubConfig", "\"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\servicehub.config.json\"" ], "Preference": 0 }, { "Path": "c:\\program files (x86)\\microsoft visual studio\\2019\\enterprise\\common7\\ide\\extensions\\qglq5p5b.btx\\TokenService\\Microsoft.Asal.TokenService.exe", "Arguments": [ "--serviceHubConfig", "\"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\servicehub.config.json\"" ], "Preference": 1 }, { "Path": "c:\\program files (x86)\\microsoft visual studio\\2019\\enterprise\\common7\\ide\\extensions\\4rin0bzc.yf5\\TokenService\\Microsoft.Asal.TokenService.exe", "Arguments": [ "--serviceHubConfig", "\"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\servicehub.config.json\"" ], "Preference": 2 } ] }

to only one valid entry (note a new extensions folder - “…\extensions\ys2aolp3.2rs”):

{ "TokenProviders": [ { "Path": "c:\\program files (x86)\\microsoft visual studio\\2019\\enterprise\\common7\\ide\\extensions\\ys2aolp3.2rs\\TokenService\\Microsoft.Asal.TokenService.exe", "Arguments": [ "--serviceHubConfig", "\"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\servicehub.config.json\"" ], "Preference": 0 } ] }

and then everything started to work again!

1reaction
loarabiacommented, Oct 5, 2019

@Liversage awesome that actually makes this much easier to dive into. Let me see if I can get someone on the ASAL side of things to weigh in next week.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Latest build 16.3.8 - Build no longer is working
Solution built fine before upgrade. Visual Studiowindows 10.0visual studio 2019 version 16.3.
Read more >
App Authentication client library for .NET - version 1.6.0
AzureServiceTokenProvider uses Visual Studio to get token. RunAs=CurrentUser, Local development, Not supported in .NET Core.
Read more >
Azure key vault - Microsoft Q&A
Exception Message: Tried to get token using Visual Studio. Access token could not be acquired. Visual Studio Token provider file not found ...
Read more >
Error while getting MSI token within App Service ...
It was working fine till recently, now we are getting below error while trying to get the MSI token. We are using Microsoft.Azure.Services....
Read more >
Visual Studio 2019 version 16.3 Release Notes
Fixed an issue where customers trying to install Microsoft.Visualstudio.Shell.15.0 NuGet package received a warning message of Framework not ...
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