Results 1 to 7 of 7

Thread: ASP.net VB Async WaitingForActivation error

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2011
    Posts
    23

    ASP.net VB Async WaitingForActivation error

    Hi, I'm using this code below. Not getting ant try/catch errors but am getting this:

    "Id = 9, Status = WaitingForActivation {1}, Method = "{null}", Result = "{Not yet computed}"

    I've been stuck for many hours and can't seem to figure this out. I hope someone can help or provide a good example.
    My task is to get MS oAuth to return a token so I can access an API.

    Thank You


    Code:
    Public Class Tforce
        Inherits System.Web.UI.Page
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles form1.Load
            Dim Test = AsyncCall(Nothing)
    
        End Sub
    
        Protected Async Function AsyncCall(ByVal e As System.EventArgs) As Task
    
            Dim clientId As String = "4e502cbc-a55f-4341-a498-69cfbe19ee7b"
            Dim clientSecret As String = "My Secret goes here "
            Dim credentials = String.Format("{0}:{1}", clientId, clientSecret)
            Dim headerValue = Convert.ToBase64String(Encoding.UTF8.GetBytes(credentials))
    
            Dim content = New FormUrlEncodedContent(New Dictionary(Of String, String) From {
                                                {"client_id", clientId},
                                                {"client_secret", clientSecret},
                                                {"grant_type", "client_crdentials"},
                                                {"scope", "https://tffproduction.onmicrosoft.com/04cc9749-dbe5-4914-b262-d866b907756b/.default"}
                                                })
    
            Dim requestMessage = New HttpRequestMessage(HttpMethod.Post, "https://login.microsoftonline.com/ca4f5969-c10f-40d4-8127-e74b691f95de/oauth2/v2.0/token")
            requestMessage.Headers.Authorization = New AuthenticationHeaderValue("Basic", headerValue)
            requestMessage.Content = content
    
            Dim responsemessage As HttpResponseMessage
    
            Dim client As New HttpClient
    
            Try
                responsemessage = Await client.SendAsync(requestMessage)
            Catch ex As Exception
                Dim showerror As String = ex.Message
            End Try
    
    
        End Function
    
    
    End Class

  2. #2
    Lively Member
    Join Date
    Jun 2017
    Posts
    81

    Re: ASP.net VB Async WaitingForActivation error

    Dim Test = await AsyncCall(Nothing)

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2011
    Posts
    23

    Re: ASP.net VB Async WaitingForActivation error

    Thanks you Black river but now I get
    Dim Test = await AsyncCall(Nothing) Expression does not a value produce a value

  4. #4
    Lively Member
    Join Date
    Jun 2017
    Posts
    81

    Re: ASP.net VB Async WaitingForActivation error

    You have a function that currently does not return anything. A function needs to return something..In your case, a Task(of something)...

    So in this case, you can just return your response content...

    Code:
    Protected Async Function AsyncCall(ByVal e As System.EventArgs) As Task(Of String)
    
        Dim clientId As String = "4e502cbc-a55f-4341-a498-69cfbe19ee7b"
        Dim clientSecret As String = "My Secret goes here "
        Dim credentials = String.Format("{0}:{1}", clientId, clientSecret)
        Dim headerValue = Convert.ToBase64String(Encoding.UTF8.GetBytes(credentials))
    
        Dim content = New FormUrlEncodedContent(New Dictionary(Of String, String) From {
                                            {"client_id", clientId},
                                            {"client_secret", clientSecret},
                                            {"grant_type", "client_credentials"},
                                            {"scope", "https://tffproduction.onmicrosoft.com/04cc9749-dbe5-4914-b262-d866b907756b/.default"}
                                            })
    
        Dim requestMessage = New HttpRequestMessage(HttpMethod.Post, "https://login.microsoftonline.com/ca4f5969-c10f-40d4-8127-e74b691f95de/oauth2/v2.0/token")
        requestMessage.Headers.Authorization = New AuthenticationHeaderValue("Basic", headerValue)
        requestMessage.Content = content
    
        Dim responsemessage As HttpResponseMessage
    
        Dim client As New HttpClient
    
        Try
            responsemessage = Await client.SendAsync(requestMessage)
            ' Check if the response is successful
            If responsemessage.IsSuccessStatusCode Then
                Dim responseContent As String = Await responsemessage.Content.ReadAsStringAsync()
                ' Return the response content
                Return responseContent
            Else
                ' If response is not successful, return an error message or handle accordingly
                Return "Error: " & responsemessage.StatusCode.ToString()
            End If
        Catch ex As Exception
            ' If an exception occurs during the request, return the error message
            Return "Error: " & ex.Message
        End Try
    
    End Function

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Aug 2011
    Posts
    23

    Re: ASP.net VB Async WaitingForActivation error

    had to add a page directive " async="true" to get the page to run.
    Then I added a button to fire off the function. After about 2 min's I received the ex.message of "Error: A task was canceled."
    This is weird. I pasted your code in and added a button to call the function

    Protected Async Sub BtnGo_Click(sender As Object, e As EventArgs) Handles BtnGo.Click
    Dim Test = Await AsyncCall(Nothing)
    End Sub

    Aghhh

    any ideas?

  6. #6
    Lively Member
    Join Date
    Jun 2017
    Posts
    81

    Re: ASP.net VB Async WaitingForActivation error

    Well, at this point you need to debug your code and figure out what is happening. Set some breakpoints inside your try..catch and then step through after the breakpoint is hit.

    If I had to guess, I would say you are running into a timeout on your httpclient.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Aug 2011
    Posts
    23

    Re: ASP.net VB Async WaitingForActivation error

    Thanks Black River. I'll give it another whirl tomorrow. Appreciate all you've done

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width