How can I find the root cause of the exception thrown by DetectImage in my BlobTrigger

Jesse Johnson 0 Reputation points
2023-12-11T18:45:15.9633333+00:00

My BlobTrigger fires when I upload my image.jpg to a Blob Container in my Storage Account. I create a temporary file in the Windows environment where my BlobTrigger is executing. I write the Blob contents to the temporary file and close the file. My code invokes the DetectImage method on the temp file. I have verified my arguments for DetectImage: Project ID, Iteration Name, and the file name of the temporary file whose contents is image.jpg. DetectImage throws the exception:

ErrorException: Operation returned an invalid status code 'NotFound'at

CustomVisionPredictionClient.DetectImageWithHttpMessagesAsync(Guid projectId, String publishedName,

Stream imageData, String application, Dictionary`2 customHeaders, CancellationToken cancellationToken)at Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction.CustomVisionPredictionClientExtensions.DetectImageAsync(ICustomVisionPredictionClient operations, Guid projectId, String publishedName, Stream imageData, String application, CancellationToken cancellationToken). My code actually has:

var result = await predictionApi.DetectImageAsync(projectID, publishedModelName, stream);

stream comes from reading the temp file: using (var stream = File.OpenRead(imageFile))

where imageFile is the temp file with the contents of my blob whose upload triggered this code. I am happy to provide the code if anyone has an idea about how I can solve this. Thank you for reading this.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,091 questions
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,916 questions
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,920 questions
Azure AI Custom Vision
Azure AI Custom Vision
An Azure artificial intelligence service and end-to-end platform for applying computer vision to specific domains.
249 questions
{count} votes

1 answer

Sort by: Most helpful
  1. MayankBargali-MSFT 70,531 Reputation points
    2023-12-18T12:38:04.05+00:00

    @Jesse Johnson Thanks for reaching out. As per the error "ErrorException: Operation returned an invalid status code 'NotFound'at" it seems that the error message you are receiving is indicating that the specified resource was not found. This could be due to a number of reasons, such as incorrect project ID, iteration name, or file name.

    To troubleshoot this issue, you can try the following steps:

    Double-check that the project ID and iteration name are correct. You can find the project ID and iteration name in the Custom Vision portal.

    Verify that the file name of the temporary file is correct and that it contains the image data that you expect.

    Check that the stream is being read correctly from the temporary file. You can try logging the length of the stream to verify that it contains the expected number of bytes.

    Ensure that the Custom Vision API endpoint and key are correct. You can check these values in the Azure portal.

    If none of these steps resolve the issue, you may need to provide more information about your code and environment to help diagnose the problem or need over one on one support to review it.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.