Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
stevenamani
Advocate II
Advocate II

Code Hanging on Acquire Token

I am attempting to acquire a token from AzureAD in a native app and while this works fine on a number of computers, I have one where the application just hangs. Here is the code:

 

public async Task<string> GetTokenAAD()

        {

            //example https://docs.microsoft.com/en-us/power-bi/developer/get-azuread-access-token

 

           var credential = new UserPasswordCredential(this.userName, this.password);

 

            var authenticationContext = new AuthenticationContext(Properties.Settings.Default.AADAUTH_URL);

 

 

            authenticationResult = await authenticationContext.AcquireTokenAsync(resourceUrl, this.clientID, credential); //code hangs here

 

            if (authenticationResult != null)

            {

                return authenticationResult.AccessToken;

            }

 

            return string.Empty;

        }

1 ACCEPTED SOLUTION

Turns out the issue was unrelated to PowerBI or Azure AD. The function was being called from a non-async function and I resolved it by adding ConfigureAwait(True) to the AcquiteTokenAsync call.

View solution in original post

2 REPLIES 2
v-micsh-msft
Microsoft Employee
Microsoft Employee

Could you please explain a bit for " application just hangs" ?

 

If it hangs in Windows, there should be application log generated for this event, please take a check under Event Viewer and see if any specific error message logged.

Further, for Windows Application hang, please check:

Extracting Information from Crash and Hang Dumps

 

Regards,

Michael

Turns out the issue was unrelated to PowerBI or Azure AD. The function was being called from a non-async function and I resolved it by adding ConfigureAwait(True) to the AcquiteTokenAsync call.

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.