Function working in Console app but not in Windows app RRS feed

  • Question

  • Public Sub Main()
            Dim client As ComputerVisionClient = Authenticate(endpoint, subscriptionKey)
            ReadFileLocal(client, READ_TEXT_LOCAL_IMAGE).Wait()
    End Sub
    Public Async Function ReadFileLocal(ByVal client As ComputerVisionClient, ByVal localFile As String) As Task
            Text1Message = "READ FILE FROM LOCAL"
            ' ######## the below line is where the computer gets stuck when calling from windows project
            Dim textHeaders = Await client.ReadInStreamAsync(File.OpenRead(localFile), language:="en")
            Dim operationLocation As String = textHeaders.OperationLocation
            Const numberOfCharsInOperationId As Integer = 36
            Dim operationId As String = operationLocation.Substring(operationLocation.Length - numberOfCharsInOperationId)
            Dim results As ReadOperationResult
                results = Await client.GetReadResultAsync(Guid.Parse(operationId))
            Loop While (results.Status = OperationStatusCodes.Running OrElse results.Status = OperationStatusCodes.NotStarted)
            Dim textUrlFileResults = results.AnalyzeResult.ReadResults
            For Each page As ReadResult In textUrlFileResults
                For Each line As Line In page.Lines
                    Text1Message += (line.Text)
        End Function

    Have to use Azure services. The function runs when try it on console app (tried both C# & VB), however when trying to run it on windows app get errors. Basically I want to return value after calling an azure service, and use it in windows app.

    Tried below:

    • created a new windows app projects, added the same module which was running in console app & tried calling.
    • created a shared project, added reference to console app & tried calling the shared function. again got stuck.

    Sunday, September 13, 2020 6:58 AM


All replies

  • If it is not difficult, show the messages and other error details. Which line raises the error?

    Sunday, September 13, 2020 7:27 AM
  • This line gives error. There is no message, simply the computer doesn't do anything.  As 'wait' is used while calling the module "ReadFileLocal(client, READ_TEXT_LOCAL_IMAGE).Wait()",

    the thread is processed asynchronously with no response

    Dim textHeaders = Await client.ReadInStreamAsync(File.OpenRead(localFile), language:="en")

    Sunday, September 13, 2020 8:37 AM
  • Maybe it is some issue with azure services. I tried with another function of azure & that too got stuck.

    gets stuck at ' Dim results As DetectResult = Await client.DetectObjectsInStreamAsync(stream)' Line.

    full code of function attached.

     Public Async Function DetectObjectsLocal(ByVal client As ComputerVisionClient, ByVal localImage As String) As Task
            Using stream As Stream = File.OpenRead(localImage)
                Dim results As DetectResult = Await client.DetectObjectsInStreamAsync(stream)
                Console.WriteLine($"Detecting objects in local image {Path.GetFileName(localImage)}...")
                Console.WriteLine("Detected objects:")
                For Each obj In results.Objects
                    Console.WriteLine($"{obj.ObjectProperty} with confidence {obj.Confidence} at location {obj.Rectangle.X}, " & $"{obj.Rectangle.X + obj.Rectangle.W}, {obj.Rectangle.Y}, {obj.Rectangle.Y + obj.Rectangle.H}")
            End Using
        End Function

    Sunday, September 13, 2020 1:06 PM
  • Hi Compvishal08,

    Since the question is more related to azure service, I have moved the thread to 'where is the forum for' forum which can help you find the correct forum to go ask questions.

    Thank you for your understanding.

    Best Regards,

    Xingyu Zhao

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, September 14, 2020 6:06 AM
  • Monday, September 14, 2020 6:53 AM