January 3, 2020

Windows 10, .NET 3.5, and TLS 1.2

One thing about Windows 10 is that even though they're all called Windows 10, each major update are sufficiently different that things can break. I rolled out Windows 10, version 1909 to all users a few weeks ago, and sure enough, something broke, maybe.

On the very first working day of 2020 at 8:30 a.m., users called in to say the program they use to upload exchange rates doesn't work and returns a cryptic error message: The underlying connection was closed: An unexpected error occured on a send.

The program is actually very simple, it connects to the Bank of Thailand's website and simply downloads the current exchange rate in Excel format. It then parses the Excel file and ports the exchange rate data into the ERP system. The error seems to suggest the file doesn't exist or there's some other connectivity error. The Bank of Thailand changed their website layout once many years ago, but I seriously doubted they would do this on the very first day of the year. Sure enough, the website still exists and a manual download of the file worked fine, so the issue must be elsewhere.

I asked the users when they started having the issue, and they said they've been having it a while, but since we were busy with end of the year stock taking and moving servers, they decided to do manual entry instead of reporting the issue. Well that sucks.

A Google search for the error message suggests that it's due to newer operating systems defaulting to TLS 1.2, but I know that the program worked fine in Windows 7, and we rolled out Windows 10 quite a while ago, and it worked until recently, and since the users weren't sure when they started having the issue, I wasn't sure if 1909 was the problem.

However, TLS sounded right since the program was developed using Visual Studio 2008 with .NET 3.5. Many solution I found on the net were impossible to do since they suggest modifying the code with SecurityProtocolType.Tls12, but my version of Visual Studio doesn't have such an option. A lot of the solutions also suggest upgrading to .NET 4.8 which is also impossible. Finally, after about three hours of searching and trying all kinds of different things I managed to find an easy to implement solution. The surprising thing about this solution is that it doesn't involve registry editing or installing a hotfix, which is much easier for me since I have the source code. I guess most of the other solutions try to modify the OS since most legacy apps probably don't have the source code available any more.

Fortunately, after the modification the program worked fine and the users are happy again. Unfortunately the program no longers works in Windows 7, but we're phasing Windows 7 out any way so I decided not to modify the program to work with both Windows 10 and Windows 7.

No comments: