0

I have Visual Studio 2010 and code in VB.NET. I wrote some software back in 2017-ish that has worked fine for the past 5 years. The program still works fine on the computer I wrote the software on. However, it has stopped working on all other computers. The problem is in my GetPicture code.

Function GetPicture(ByVal url As String) As Image
    GlobalVariables.PictureError = False
    Try
        url = Trim(url)
        url = ReplaceText(url, "https", "http")
        Dim web_client As New WebClient()
        Const IE8 As String = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648) "
        web_client.Headers.Add("user-agent", IE8)
        If Mid(url, 1, 5).ToLower <> "http:" Then url = "http:" & url
        Dim image_stream As New  _
            MemoryStream(web_client.DownloadData(url))
        Return Image.FromStream(image_stream)
        web_client.Dispose()
    Catch ex As Exception
        GlobalVariables.PictureError = True
    End Try
    Return Nothing
End Function

I use this code to download pictures from the web. Here is a sample URL it would download from: http://img.gsmls.com/imagedb/highres/53/104300640_0.jpg

On the "other" computers, I am getting this error: "Could not create TSL/SSL secure channel." Based on my googling here, I have to change to TLS1.2, which VB.NET 2010 does not support. I guess the image server has been upgraded and now requires the new framework?

I am curious if anyone has any insight as to why this would still work on the computer I use to code the software, and if there's anything I could do to right this on the other computers? I would prefer to avoid updating to a new version of Visual Studio.

brand0
  • 11
  • 4
  • 1
    `I guess the image server has been upgraded and now requires the new framework?` why would it continue working on your dev machine? – djv Mar 25 '22 at 19:35
  • this is my question exactly lol – brand0 Mar 25 '22 at 19:45
  • Your dev machine, unless it's Windows 7 and never updated, would have .NET 4.8 by now, even the app targeting 4.0 will run on 4.8 because 4.8 replaces the existing runtime, does the other computers get Windows updates? – Martheen Mar 25 '22 at 19:49
  • @Martheen Visual Studio 2010 can't target 4.8. I think the max version is 4.0. If the app targets 4.0 it will not use the latest runtime installed, which is cumulative (it will use the 4.0 Framework in any case) – djv Mar 25 '22 at 19:51
  • I can replicate the bug with my VS 2010, and adding `ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;` at the beginning fix the problem, not sure what actually made the dev machine works then without the workaround, perhaps one of https://stackoverflow.com/questions/33761919/tls-1-2-in-net-framework-4-0 was applied in the past – Martheen Mar 25 '22 at 20:10
  • I got it! Nevermind! You're the best! Here is the fix in VB.NET: – brand0 Mar 25 '22 at 20:22
  • ServicePointManager.SecurityProtocol = CType(3072, SecurityProtocolType) – brand0 Mar 25 '22 at 20:28

1 Answers1

0

Thanks to Martheen for the solution:

ServicePointManager.SecurityProtocol = CType(3072, SecurityProtocolType)

brand0
  • 11
  • 4