SSL Connection could not be established with Azure Document Intelligence for .NET CORE

Shel, S 0 Reputation points
2025-02-13T04:08:58.6966667+00:00

Using this sample below from Azure Samples for Document Intelligence

https://github.com/Azure-Samples/document-intelligence-code-samples/blob/main/.NET(v4.0)/Quickstarts/Samples/Sample_ExtractLayout.cs

Get this error below for this call - await client.AnalyzeDocumentAsync(WaitUntil.Completed, "prebuilt-layout", BinaryData.FromBytes(docFileBytes));

User's image

I see that there is a solution for python where one can specify connection_verify=False

Is there a similar one for .NET core?

Azure AI Document Intelligence
Azure AI Document Intelligence
An Azure service that turns documents into usable data. Previously known as Azure Form Recognizer.
1,927 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Sina Salam 18,046 Reputation points
    2025-02-14T09:46:58.1633333+00:00

    Hello Shel, S,

    Welcome to the Microsoft Q&A and thank you for posting your questions here.

    I understand that you SSL connection could not be established with Azure Document Intelligence for .NET CORE.

    Regarding your question:

    I see that there is a solution for python where one can specify connection_verify=False Is there a similar one for .NET core?

    Yes, in .NET Core, you can achieve the equivalent of connection_verify=False (used in Python) by disabling SSL certificate validation. By creating an HttpClientHandler that ignores SSL certificate errors and use it with DocumentIntelligenceClient:

    using System;
    using System.Net.Http;
    using System.Security.Cryptography.X509Certificates;
    using Azure;
    using Azure.AI.DocumentIntelligence;
    using Azure.Core.Pipeline;
    // Create an HttpClientHandler that ignores SSL certificate validation
    HttpClientHandler httpClientHandler = new HttpClientHandler
    {
        ServerCertificateCustomValidationCallback = (message, certificate, chain, sslPolicyErrors) => true
    };
    // Create an HttpClient using the handler
    HttpClient httpClient = new HttpClient(httpClientHandler);
    // Use the HttpClient in DocumentIntelligenceClient
    var clientOptions = new DocumentIntelligenceClientOptions
    {
        Transport = new HttpClientTransport(httpClient)
    };
    var client = new DocumentIntelligenceClient(new Uri("<your-endpoint>"), new AzureKeyCredential("<your-api-key>"), clientOptions);
    
    

    Warning: This disables SSL validation, making the connection insecure. Use it only for debugging! NOT for production environment.

    Alternatively, if the SSL issue is due to outdated TLS settings, you can force the correct TLS version:

    using System.Net;
    using System.Net.Http;
    // Set TLS version explicitly
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls13;
    

    This ensures your application supports the latest TLS versions while keeping SSL validation enabled.

    I hope this is helpful! Do not hesitate to let me know if you have any other questions.


    Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful.

    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.