microsoft / Cognitive-Vision-Windows

Windows SDK for the Microsoft Computer Vision API, part of Cognitive Services
https://www.microsoft.com/cognitive-services/en-us/computer-vision-api
Other
166 stars 150 forks source link

WPF sample builds and runs but throws exception on Analyze #19

Closed briannoyes closed 7 years ago

briannoyes commented 7 years ago

Here is what gets dumped in the console: [16:11:51.353827]: VisionServiceClient is created [16:11:51.355825]: Calling VisionServiceClient.AnalyzeImageAsync()... [16:11:53.596602]: Microsoft.ProjectOxford.Vision.ClientException: Exception of type 'Microsoft.ProjectOxford.Vision.ClientException' was thrown. at Microsoft.ProjectOxford.Vision.VisionServiceClient.HandleException(Exception exception) at Microsoft.ProjectOxford.Vision.VisionServiceClient.b__42_1[TRequest,TResponse](Exception e) at System.AggregateException.Handle(Func2 predicate) at Microsoft.ProjectOxford.Vision.VisionServiceClient.<SendAsync>d__422.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.ProjectOxford.Vision.VisionServiceClient.d21`1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.ProjectOxford.Vision.VisionServiceClient.d20.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at VisionAPI_WPF_Samples.AnalyzePage.<UploadAndAnalyzeImage>d__1.MoveNext() in C:\Demos\Cortana\Cognitive-Vision-Windows\Sample-WPF\AnalyzePage.xaml.cs:line 86 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at VisionAPI_WPF_Samples.AnalyzePage.d3.MoveNext() in C:\Demos\Cortana\Cognitive-Vision-Windows\Sample-WPF\AnalyzePage.xaml.cs:line 141 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at VisionAPI_WPF_Samples.ImageScenarioPage.d15.MoveNext() in C:\Demos\Cortana\Cognitive-Vision-Windows\Sample-WPF\ImageScenarioPage.cs:line 90

VergaraF commented 7 years ago

I am on the same boat. It throws an exception on every feature. When I tried OCR, it says my key is not valid but I am literally copying and pasting from the Microsoft website... the key is indeed valid.

VergaraF commented 7 years ago

The error is somewhere on the api key. Despite being given an official key from Microsoft, the request doesn't accept it. I get a 401 error.

cthrash commented 7 years ago

Are either of you using the 'Try Free' API key? If so, you must use the VisionServiceClient.ctor override, and provide the host address (2nd arg) of https://westcentralus.api.cognitive.microsoft.com/vision/v1.0.

VergaraF commented 7 years ago

https://stackoverflow.com/questions/44094186/microsoft-cognitive-services-computer-vision-invalid-subscription-key here a solution

briannoyes commented 7 years ago

Aligning the region my keys were for with the region being called fixed the problem for me. Since the region being called is buried in the code, I'd suggest making that a prompt along with the key, or somehow make it clear that the code has a specific region buried in the code that they will need to change if their keys are from a different region.

chsienki commented 7 years ago

Thanks @briannoyes This was a recent change, and we haven't yet updated the sample apps to support the region specificity, its on our backlog and we'll update the apps to prompt for a region in the future.

cthrash commented 7 years ago

I haven't had the time to try it, but does this solve the issue? Worth a try

briannoyes commented 7 years ago

yep, looks like that will help