Whats happenning RRS feed

  • Question

  • The code I am pasting in below was derived from a piece of documentation I believe it was intended as an example of what I am focusing on but I ran into a mysterious problem.  When I try to build it I will see the diagnostic "SUB MAIN WAS NOT FOUND IN MODULE .."  I cannot fathom where I am going wrong.  Can someone help?

    Imports System
    Imports System.IO
    Imports System.Net
    Imports System.Text
    Namespace Examples.System.Net
        Module Module1

            Public Class WebRequestGetExample

                Public Shared Sub Main()
                    ' Create a request for the URL.   
                    Dim request As WebRequest = _
                    ' If required by the server, set the credentials.  
                    request.Credentials = CredentialCache.DefaultCredentials
                    ' Get the response.  
                    Dim response As WebResponse = request.GetResponse()
                    ' Display the status.  
                    Console.WriteLine(CType(response, HttpWebResponse).StatusDescription)
                    ' Get the stream containing content returned by the server.  
                    Dim dataStream As Stream = response.GetResponseStream()
                    ' Open the stream using a StreamReader for easy access.  
                    Dim reader As New StreamReader(dataStream)
                    ' Read the content.  
                    Dim responseFromServer As String = reader.ReadToEnd()
                    ' Display the content.  
                    ' Clean up the streams and the response.  
                End Sub

            End Class
        End Module
    End Namespace

    • Edited by elisch123 Tuesday, February 21, 2017 7:52 PM
    Tuesday, February 21, 2017 7:50 PM


  • Is this a console application or a Windows Forms application?

    Ultimately you need to move Sub Main out of the class and put it directly in the Module without the Shared access modifier.  If this is a Forms application you'll also have to change the startup object to Sub Main.

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    • Marked as answer by elisch123 Saturday, February 25, 2017 6:21 PM
    Tuesday, February 21, 2017 7:57 PM