I am working with Visual Basic Studio 2013 and one of my forms requires the use of a web client component. I added Web Client to my toolbox and easily added it to my form. When VBStudio cooperates the form does everything as it should perfectly. However, when I loaded it for the first time and tried to debug it told me that adding the component to my form added some lines of code that have been deprecated. This popped up the form#.Designer.vb with the code and I could see the two lines that were causing the problem. I deleted them and saved the vb file and had no problems.

Here are the two deprecated lines:

        Me.WebClient.AllowReadStreamBuffering = False
        Me.WebClient.AllowWriteStreamBuffering = False

And here is the error that is thrown:

Error   4   'Public Property AllowReadStreamBuffering As Boolean' is obsolete: 'This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.'.   C:\Users\Me\Documents\Visual Studio 2013\Projects\WindowsApplication5\WindowsApplication5\Form7.Designer.vb 150 9   WindowsApplication5

Now, every once in a while VBStudio puts those two lines back in and throws the errors when debugging. I am not sure if this would cause crashes or would happen if I deleted the lines and then built my program for release. But either way I am curious as to how I could go about permanently ridding my application of those two lines and not having them re-inserted.

Any ideas will be greatly appreciated!

Dani AI

Generated

Brief diagnosis: the Windows Forms designer is serializing non-default WebClient properties into the FormName.Designer.vb file, so manually deleting those lines only hides the symptom — the designer will re‑write them the next time it decides the component needs serializing. The two WebClient properties flagged as obsolete in newer .NET builds are being reinserted by the designer, which is why compilation fails intermittently for . was right that changing the target framework can avoid the compiler error, but that is a compatibility workaround rather than a durable fix.

Practical, safe remedies (preferred order):

  • Remove the WebClient component from the form (delete it from the component tray) and stop using the designer for that instance. Then manage the client in code only. Example patterns (VB):

    ' code-managed WebClient
    Private client As System.Net.WebClient
    
    Private Sub Form_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        client = New System.Net.WebClient()
        ' use client here
    End Sub

    Or, for a more modern approach, use HttpClient:

    Private Shared ReadOnly http As New System.Net.Http.HttpClient()
    
    Private Async Function FetchAsync(url As String) As Task(Of String)
        Return Await http.GetStringAsync(url)
    End Function
  • After removing the designer component, clean up any leftover serialization: open the form .resx and the Designer.vb to remove the component declarations/entries, then do a full solution search for the obsolete property names and remove any stray references. Rebuild.

Notes and cautions: editing Designer.vb repeatedly is fragile because the designer owns that file. Programmatic instantiation or migrating to HttpClient prevents the designer from trying to serialize deprecated properties. Downgrading the target framework will stop the error but carries future maintenance costs; prefer code-managed clients or migrating to HttpClient for long-term stability.

Hi

The MSDN documentation states that this will not compile in .NET versions 4.5.2 or greater. So, if you need to use this and have no requirement to use .NET 4.5.2 or greater then simply change your target framework to a lower version. This may not be the most suitable resolution depending on your future requirements.

A quick google search also led me to some solutions such as removing the WebClient component from your form and then adding it again. Alternatively, ensure you are using the correct version of System.Net and simply declare your web client in code rather than using the component.

HTH

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.