Type: NullReferenceException, Exception Message: Object reference not set to an instance of an object - InfoPath Dev
in

InfoPath Dev

Type: NullReferenceException, Exception Message: Object reference not set to an instance of an object

Last post 03-04-2011 08:23 PM by Jimmy. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 03-04-2011 07:55 AM

    • g21cincy
    • Top 150 Contributor
    • Joined on 10-20-2008
    • Cincinnati, OH
    • Posts 64

    Type: NullReferenceException, Exception Message: Object reference not set to an instance of an object

    Hello,

     I'm getting this error when trying to send an email out. Below is the code I'm using. I'm taking the data from a repeating table from each row where the "Add Trainee" checkbox is checked and sending  separate email(s) out to the RequestorEmail field(s) to let them know their request has been filled. Any help would be greatly appreciated

    Private Sub SendEmailToRequestor(ByVal GoToPacketSelection As Boolean)

    Dim Nav As XPathNavigator = Me.DataSources("Training Classes").CreateNavigator()

    Dim rows As XPathNodeIterator = Nav.Select("/dfs:myFields/dfs:dataFields/d:tblTrainingClasses", NamespaceManager)

    Dim iCounter As Integer = 1While rows.MoveNext()

    If GetValue("/dfs:myFields/dfs:dataFields/d:tblTrainingClasses[" & iCounter & "]/@AddTrainee", Nav) = "yes" Then

    Dim RequestorName As String = MainDataSource.CreateNavigator().SelectSingleNode("/dfs:myFields/my:RequestorName", NamespaceManager).Value

    Dim RequestorEmail As String = MainDataSource.CreateNavigator().SelectSingleNode("/dfs:myFields/dfs:dataFields/d:tblTrainingClasses[" & iCounter & "]/@RequestorEmail", NamespaceManager).Value

    Dim TraineeName As String = MainDataSource.CreateNavigator().SelectSingleNode("/dfs:myFields/dfs:dataFields/d:tblTrainingClasses[" & iCounter & "]/@NameOfTrainee", NamespaceManager).Value

    Dim Priority As String = MainDataSource.CreateNavigator().SelectSingleNode("/dfs:myFields/dfs:dataFields/d:tblTrainingClasses[" & iCounter & "]/@Priority", NamespaceManager).Value

    Dim EduationalCategory As String = MainDataSource.CreateNavigator().SelectSingleNode("/dfs:myFields/dfs:dataFields/d:tblTrainingClasses[" & iCounter & "]/@EduationalCategory", NamespaceManager).Value

    Dim Department As String = MainDataSource.CreateNavigator().SelectSingleNode("/dfs:myFields/dfs:dataFields/d:tblTrainingClasses[" & iCounter & "]/@Department", NamespaceManager).Value

    Dim ClassName As String = MainDataSource.CreateNavigator().SelectSingleNode("/dfs:myFields/dfs:queryFields/q:tblTrainingClasses/@ClassQuery", NamespaceManager).Value

    Dim DateEnrolled As Date = MainDataSource.CreateNavigator().SelectSingleNode("/dfs:myFields/dfs:queryFields/q:tblTrainingClasses/@TimeQuery", NamespaceManager).Value

    Dim TimeEnrolled As String = MainDataSource.CreateNavigator().SelectSingleNode("/dfs:myFields/dfs:queryFields/q:tblTrainingClasses/@TimeQuery", NamespaceManager).Value

    Dim fromAddress As MailAddress = New MailAddress("[email protected]")

    Dim toAddress As MailAddress = New MailAddress(RequestorEmail)

    Dim msgmail As MailMessage = New MailMessage(fromAddress, toAddress)

    Select Case RequestorEmail

    Case Is = "[email protected]"

    RequestorName = "name"

    Case Is = "[email protected]"

    RequestorName = "name1"

    Case Is = "[email protected]"

    RequestorName = "name2"

    End Select

    msgmail.Subject = "MRSI Training form Enroll Request Fulfilled"

    msgmail.Body = RequestorName + "," + System.Environment.NewLine + _

    " " + System.Environment.NewLine + _

    "An enroll request that you submitted has been fulfilled with the following information:" + System.Environment.NewLine + _

    " " + System.Environment.NewLine + _

    "Trainee Name: " + TraineeName + System.Environment.NewLine + _

    "Priority: " + Priority + System.Environment.NewLine + _

    "Educational Category: " + EduationalCategory + System.Environment.NewLine + _

    "Department: " + Department + System.Environment.NewLine + _

    "Class: " + ClassName + System.Environment.NewLine + _ "Date: " + DateEnrolled + System.Environment.NewLine + _

    "Time: " + TimeEnrolled + " "

    Dim client As SmtpClient = New SmtpClient("exchange_server_here")

    client.Credentials = New System.Net.NetworkCredential("username", "password")

    client.Send(msgmail)

    End If

    iCounter += 1

    End While

    End Sub

  • 03-04-2011 07:59 AM In reply to

    Re: Type: NullReferenceException, Exception Message: Object reference not set to an instance of an object

    Most likely there's an issue with one of the XPaths you're using.  Have you tried walking the code in the debugger to see where the error is happening?

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 03-04-2011 08:23 AM In reply to

    • g21cincy
    • Top 150 Contributor
    • Joined on 10-20-2008
    • Cincinnati, OH
    • Posts 64

    Re: Type: NullReferenceException, Exception Message: Object reference not set to an instance of an object

    I ran the code through the debugger and it gave me these troubleshooting tips:

    Use the "new" keyword to creat an object instance.

    Check to determine if the object is null before calling the method.

  • 03-04-2011 08:31 AM In reply to

    Re: Type: NullReferenceException, Exception Message: Object reference not set to an instance of an object

    Were you able to determine which line was causing the error?

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 03-04-2011 08:50 AM In reply to

    • g21cincy
    • Top 150 Contributor
    • Joined on 10-20-2008
    • Cincinnati, OH
    • Posts 64

    Re: Type: NullReferenceException, Exception Message: Object reference not set to an instance of an object

    I'm pretty sure it's all the lines with the [" & iCounter ] in them but I'm not sure how to fix my problem.

  • 03-04-2011 08:23 PM In reply to

    Re: Type: NullReferenceException, Exception Message: Object reference not set to an instance of an object

    Could you attach a screenshot of your main data source?

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
Page 1 of 1 (6 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.