MicrosoftDocs / azure-docs

Open source documentation of Microsoft Azure
https://docs.microsoft.com/azure
Creative Commons Attribution 4.0 International
10.26k stars 21.43k forks source link

Code working in Console app but not in Windows app (Dot.Net) #62539

Closed compvishal closed 4 years ago

compvishal commented 4 years ago

I am a Dot.Net programmer. 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:

Check the below code. The line marked in bold 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

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 Thread.Sleep(2000) Const numberOfCharsInOperationId As Integer = 36 Dim operationId As String = operationLocation.Substring(operationLocation.Length - numberOfCharsInOperationId) Dim results As ReadOperationResult

    Do
        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
            'Console.WriteLine(line.Text)
            Text1Message += (line.Text)
        Next
    Next

    'Console.WriteLine()
End Function

Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

RohitMungi-MSFT commented 4 years ago

@compvishal Thanks for the question. If you are building a windows app you can try to use our intelligent kiosk app as a sample to replicate reading the local file for any of our cognitive services API. Here is the link to the intelligent kiosk repo. You can try to read the file as implemented in our ImagePickerControl class.

compvishal commented 4 years ago

Hi @RohitMungi-MSFT, thanks for reply. The sample code is of Universal Windows Platform Development. I am trying it. However wont the Microsoft.Azure.CognitiveServices.Vision.ComputerVision run on simple windows app on dot.net framework?

RohitMungi-MSFT commented 4 years ago

@compvishal The usage of the package is only dependent on the dependencies as listed in the nuget page:

.NETFramework 4.5.2 Microsoft.Rest.ClientRuntime (>= 2.3.18 && < 3.0.0) Microsoft.Rest.ClientRuntime.Azure (>= 3.3.18 && < 4.0.0) Newtonsoft.Json (>= 6.0.8)

.NETStandard 1.4 Microsoft.Rest.ClientRuntime (>= 2.3.18 && < 3.0.0) Microsoft.Rest.ClientRuntime.Azure (>= 3.3.18 && < 4.0.0) NETStandard.Library (>= 1.6.1) Newtonsoft.Json (>= 10.0.3) System.Net.Http (>= 4.3.0)

compvishal commented 4 years ago

Thanks. Then my original question remains. Why is it not working on dot.net framework? Further the kiosk sample is giving it's own errors. Pl check the attached screenshot. 2020-09-15

RohitMungi-MSFT commented 4 years ago

@compvishal You can publish your solution on github and reference it with an issue on our SDK repo. This forum is primarily for issues related to this document and quickstart's published by the content authors/document writers.

compvishal commented 4 years ago

I am sorry if bit confused. The image is error showing in 'this document', i.e. Kiosk app only.

RohitMungi-MSFT commented 4 years ago

The sample worked out of the box without any errors. image

I think you might need to resolve the missing references.

RohitMungi-MSFT commented 4 years ago

We will now proceed to close this thread as the quickstart document works fine. If there are further questions regarding this matter, please tag @RohitMungi-MSFT in your reply.