Task Waiting for activation issue RRS feed

  • Question

  • Hi,

    I am facing issue with the below code , trying to access the token from the active directory but is not responding properly, when i try with the non await method then it gives response : WatingForActivation and when i try by await call it is just gets hungs up.

       static void Main(string[] args)
            static async void GetToken()
                var ActiveDirectoryEndpoint = "https://login.microsoftonline.com/";
                    var ActiveDirectoryTenantId = "XXXXXXXXXXXXXXXXXXXXXX";
                    var ApplicationId = "XXXXXXXXXXXXXXXX";
                    var Password = "XXXXXXXXXXXXXXXXXXXXXXXXXX";
                    var WindowsManagementUri = "https://management.core.windows.net/";
                    AuthenticationContext context = new AuthenticationContext(ActiveDirectoryEndpoint + ActiveDirectoryTenantId);
                    ClientCredential credential = new ClientCredential(ApplicationId, Password);
                    var authenticationResult = await context.AcquireTokenAsync(WindowsManagementUri, credential);
                catch (Exception)
                    throw new InvalidOperationException("Failed to acquire token");

    Can any one help me in this issue.

    Monday, March 26, 2018 7:51 PM

All replies