Unable to use HttpClient from UDF, but static method is able to perform request in Console Application

66 views
Skip to first unread message

Connor Keevill

unread,
Jan 14, 2022, 11:04:23 AM1/14/22
to Excel-DNA
Hi Govert, 

I've having a weird problem where I'm able to run a function in a console application, but not the same function from Excel.Screenshot 2022-01-14 160144.png
Here is the method I am trying to call.

If I call from an console application it correctly outputs my IP address (as it should), however calling the corresponding UDF in Excel causes the following error: 

An error has occured: System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.

   at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)

   at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)

   --- End of inner exception stack trace ---

   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()

   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()

   at SignalAddIn.SignalConfigTestUtils.<SigTestServerConnection>d__1.MoveNext()

Any ideas what could be going wrong here? Guessing it's something related to the async nature of the method, but I don't know what.

Thanks for any help, 
Connor

Govert van Drimmelen

unread,
Jan 27, 2022, 4:38:49 PM1/27/22
to Excel-DNA
Hi Connor 

I wonder whether this is the same issue you have:  TLS1.2, Excel and .NET (google.com)

-Govert

Bart Duijndam

unread,
Jan 28, 2022, 3:58:54 PM1/28/22
to Excel-DNA
Hi all,

I just posted this in a different conversation. I believe I had a similar issue. It was solved by adding one line to AutOpen()

            // the next line is essential to prevent file-open errors.
            ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;


Maybe this is of use.

Cheers,
Bart
Reply all
Reply to author
Forward
0 new messages