I have a c# Framework 4.7.2 Com visible library that calls a web api.
Unit tests in the VS2017 C# IDE library work fine.
However if I try to call via VB6 I get
System.IO.IOException unable to read data from the transport connection: An existing connection was forcibly closed by the rempte host.
System.Net.Sockets.SocketException
I am running Windows 10
I call as administrator
C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm /codebase /verbose /tlb:SBD.ComBridge.tlb C:\dev\SBD.ComBridge.dll
to create the .dll and .tlb
I also tried running regasm from the VS2017 command prompt as administrator
RegAsm reports that the libraries register successfully.
In Vb6 the (simplified) code is
Dim o As SBD_ComBridge.BridgeImplementation
Set o = New dBridgeImplementation
o.SetOrderDates id
set o = nothing
In BridgeImplementation the (simplified) code is
[DispId(25)]
[ComVisible(true)]
public void SetOrderDates(int Id)
{
PackAndSend.SetReadByInfo(Id) // calls freight service
}
I know that the code calling the service from within SetReadyByInfo works because my unit test passes when I run it in VS2017
Unfortunately I have been asked not to post the code. However I know that the vb6 code calls Com correctly because there are other methods I call without errors.
I had a similar issue with MYOB api and TLS the solution was to upgrade the Framework. However I can't upgrade the VB6 framework ( the large re-write is not an option) Probably I will just make a .Exe and shell out to it.
[Update]
The link Simon Mourier gave me solves it. If I add
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
then my com call works on VB6
As the link points out,
This isn't a good solution since it hard codes what TLS version to use, so it wouldn't use TLS 1.3 in future
PackAndSend.SetReadByInfo
a blocking call? It is a .NET exception so I think the next set of code to post is that. – tcarvin