none
Object Reference not set to an instance of an object.

    Question

  • Hello All!  I'm trying to build a .dll for an .aspx page for my employer.  When I tried to compile the first time I got an error.  The original code is: (error in bold/italic/underline)

    Error    1    'list' is already declared as a parameter of this method.    C:\Users\Mikel\Desktop\Website\App_Web_tlmtcf92_Source\SecureSite\crm.vb    2144    17    App_Web_tlmtcf92

    Private Sub LoadLinkOptions(ByVal List As CheckBoxList, ByVal LabelText As Label, ByVal Group As String)
                Dim list As CheckBoxList = List
                list.Items.Clear()
                list = Nothing
                Dim connection As New SqlConnection(Conversions.ToString(SiteFunctions.CSCRM))
                Dim command As New SqlCommand
                connection.Open()
                command.Connection = connection
                command.CommandText = String.Format("ListLinkOptions {0}", Group)
                Dim reader As SqlDataReader = command.ExecuteReader
                Do While reader.Read
                    list.Items.Add(New ListItem(Conversions.ToString(reader.Item("Description")), Conversions.ToString(reader.Item("OptionID"))))
                    LabelText.Text = Conversions.ToString(Operators.ConcatenateObject(reader.Item("GroupDescription"), ":"))
                Loop
                reader.Close()
                connection.Close()
                connection = Nothing
                command = Nothing
                If (list.Items.Count = 1) Then
                    list.Items.Item(0).Selected = True
                End If
            End Sub

     

    So naturally I tried to just change the "list" to "list1" and the error went away.  I rebuilt the .dll, put it in the bin folder, opened up the site and got this:

     

    Object reference not set to an instance of an object.

     

    Description: An unhandled exception occurred during the execution of the current web request.  Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Soucre Error:

    An unhandled exception occurred during the execution of the current web request.  Please review the stack trace for more information about the error and where it originated in the code.

    Stack Trace:

    [NullReferenceExcepttion: Object reference not set to an instance of an object.]

    SecureSite.crm.LoadLinkOptions(CheckBoxList List, Label LabelText, String Group) +257

    SecureSite.crm.BuildLinkToList(String Value) +1706

    SecureSite.crm.SelectWorkingFirm() +97

    SecureSite.crm.Page_Load(Object Sender, EventArgs e) +1343

    System.Web.UI.Control.OnLoad(EventArgs e) +99

    System.Web.UI.Control.LoadRecursive() +50

    System.Web. UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

     

    So what am I missing here?  I leave it as it was when I decompiled it, it throws an error in VB, if I "fix" it, it throws an error in the browser.  Help!

     


    The Ox is slow, but the Earth is patient.
    Wednesday, July 13, 2011 8:36 PM

Answers

  • I fixed it by changing the Dim list, list.items.clear(), and list = nothing to something else, and leaving the rest of the "list"'s alone. 

    The Ox is slow, but the Earth is patient.
    • Marked as answer by Malleus55 Wednesday, July 13, 2011 9:16 PM
    Wednesday, July 13, 2011 9:15 PM

All replies

  • Hello Malleus55,

     

    try to replace

     

    Dim list As CheckBoxList = List
     
    

    Whith

     

     

    Dim list1 As New CheckBoxList = List
     
    

     

    The code complete

     

     

    Private Sub LoadLinkOptions(ByVal List As CheckBoxList, ByVal LabelText As Label, ByVal Group As String)
        Dim list1 As New CheckBoxList = List
        list1.Items.Clear()
        list1 = Nothing
        Dim connection As New SqlConnection(Conversions.ToString(SiteFunctions.CSCRM))
        Dim command As New SqlCommand
        connection.Open()
        command.Connection = connection
        command.CommandText = String.Format("ListLinkOptions {0}", Group)
        Dim reader As SqlDataReader = command.ExecuteReader
        Do While reader.Read
         list1.Items.Add(New ListItem(Conversions.ToString(reader.Item("Description")), Conversions.ToString(reader.Item("OptionID"))))
         LabelText.Text = Conversions.ToString(Operators.ConcatenateObject(reader.Item("GroupDescription"), ":"))
        Loop
        reader.Close()
        connection.Close()
        connection = Nothing
        command = Nothing
        If (list1.Items.Count = 1) Then
         list1.Items.Item(0).Selected = True
        End If
       End Sub
    

    Bye

     

     


    Carmelo La Monica  http://community.visual-basic.it/carmelolamonica/



    Wednesday, July 13, 2011 8:53 PM
  • I tried that and when I did the rebuild and tried to open the page I got the "Object reference not set to an instance of an object." error.

    The Ox is slow, but the Earth is patient.
    • Marked as answer by Malleus55 Wednesday, July 13, 2011 9:14 PM
    • Unmarked as answer by Malleus55 Wednesday, July 13, 2011 9:14 PM
    Wednesday, July 13, 2011 9:04 PM
  • I fixed it by changing the Dim list, list.items.clear(), and list = nothing to something else, and leaving the rest of the "list"'s alone. 

    The Ox is slow, but the Earth is patient.
    • Marked as answer by Malleus55 Wednesday, July 13, 2011 9:16 PM
    Wednesday, July 13, 2011 9:15 PM
  • LoadLinkOptions must be called with a CheckListBox, a Label and a String as parameters. Are you sure that whatever method is calling LoadLinkOptions has initialised all three parameters. For example, is the caller missing a List = New ChecklistBox.
    Wednesday, July 13, 2011 9:17 PM