Bug in Computer Vision Client ReadInStreamAsync Invalid URI format using in Xamarin.Forms

khambley 1 Reputation point
2022-04-16T15:38:56.697+00:00

So I am capturing a photo and opening a stream using Xamarin.Essentials 1.7 MediaPicker built into Essentials.
When I call the ReadInStreamAsync(stream) method in Computer Vision Client, I get an error and my Xamarin.Forms app breaks inside the method: 'Invalid URI: The format of the URI could not be determined.'
This is the steam.Name value - '/data/user/0/com.companyname.xamphotoappdemo2/cache/2203693cc04e0be7f4f024d5f9499e13/198fd32db9cc4be38a493325974fa138/d964251252fc4963aca94339d73a8007.jpg'

var stream = await file.OpenReadAsync();

chosenImage.Source = ImageSource.FromStream(() => stream);

// 2. Add OCR logic.

var client = Authenticate(ApiSettings.subscriptionKey, ApiSettings.endpoint);

var text = await client.ReadInStreamAsync(stream);

//after the request, get the operation location
 string operationLocation = text.OperationLocation;

//we only need the operation ID, not the whole URL
const int numberOfCharsInOperationId = 36;
 string operationId = operationLocation.Substring(operationLocation.Length - numberOfCharsInOperationId);

                    //Get the ocr read results
                    ReadOperationResult results;
                    do
                    {
                        results = await client.GetReadResultAsync(Guid.Parse(operationId));
                    }
                    while ((results.Status == OperationStatusCodes.Running || results.Status == OperationStatusCodes.NotStarted));

                    var readResults = results.AnalyzeResult.ReadResults;

                    var expirationDates = from page in readResults
                                          from line in page.Lines
                                          where line.Text.Contains("EXPIRES") && line.Words.Count == 4
                                          select line.Words[3].Text;

                    expirationDate.Text = expirationDates.ToString();

Is this a known issue / bug?

Azure Computer Vision
Azure Computer Vision
An Azure artificial intelligence service that analyzes content in images and video.
335 questions
{count} votes