locked
E-Mail RRS feed

  • Question

  • User-1832071357 posted

    I thought I had it fixed.

    Server Error in '/' Application.
    --------------------------------------------------------------------------------

    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.

    Source Error:


    Line 162:            For Each str As String In usernames
    Line 163:                mem = Membership.GetUser(str)
    Line 164:                Dim gui As New Guid(mem.ProviderUserKey.ToString)
    Line 165:                Dim name As String = GetName(gui)
    Line 166:                Dim address As New MailAddress(mem.Email, name)
     

    Source File:X:\HostingSpaces\XXXXXXXXXXX.com\XXXXXXXXXX.XXXX\xxxxxxx\admin\Email.aspx.vb    Line: 164

    Stack Trace:


    [NullReferenceException: Object reference not set to an instance of an object.]
       Admin_Email.GetRecipients() in e:\HostingSpaces\XXXXXXX.com\XXXXXXXXXX.net\wwwroot\admin\Email.aspx.vb:164
       Admin_Email.btnSend_Click(Object sender, EventArgs e) in X:\HostingSpaces\XXXXXXX.com\XXXXXXXs.xXX\xXXXXX\admin\Email.aspx.vb:50
       System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
       System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

     

     How to Fix?

    LHR

    Friday, February 12, 2010 7:10 PM

All replies

  • User-1157892548 posted

    Do a null check before using the object inside the loop like below.

    For Each str As String In usernames
                    mem = Membership.GetUser(str)

               if mem is not nothing then
                    Dim gui As New Guid(mem.ProviderUserKey.ToString)
                    Dim name As String = GetName(gui)
                    Dim address As New MailAddress(mem.Email, name)

              end if

     

    Friday, February 12, 2010 10:12 PM
  • User-1832071357 posted

     

    I added the code

    For Each str As String In usernames
                    mem = Membership.GetUser(str)

               if mem is not nothing then
                    Dim gui As New Guid(mem.ProviderUserKey.ToString)
                    Dim name As String = GetName(gui)
                    Dim address As New MailAddress(mem.Email, name)

              end if

    Received this error

    -----------------------------------------------------------------------------------------------------------------------------------------

    Compilation Error

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: BC30020: 'Is' requires operands that have reference types, but this operand has the value type 'Integer'.

    Source Error:

    Line 160:            Dim mem As MembershipUser
    Line 161:
    Line 162:            If mem Is Not Nothing Then
    Line 163:                Dim gui As New Guid(mem.ProviderUserKey.ToString)
    Line 164:                Dim name As String = GetName(gui)

    Source File: C:\Users\Buddy\Documents\Club Web\sonorapasssno-goers\Admin\Email.aspx.vb    Line: 162

    Saturday, February 13, 2010 12:01 AM
  • User-1157892548 posted

    Dim mem As MembershipUser is only declaring the mem object.

    I couldn't find the code that initialize mem object.

    mem = Membership.GetUser(str)

    Write the if condition after the above line of code only.

    Saturday, February 13, 2010 11:35 PM
  • User-1832071357 posted

    I am a newbe to this. Where do you want the code placed?

    For Each str As String In usernames
                    mem = Membership.GetUser(str)

               if mem is not nothing then
                    Dim gui As New Guid(mem.ProviderUserKey.ToString)
                    Dim name As String = GetName(gui)
                    Dim address As New MailAddress(mem.Email, name)

              end if

    Here what the code is.

     

     

     

    Next

    Dim mem As MembershipUser

    mem = Membership.GetUser(str)

    Dim mem As MembershipUserFor Each str As String In usernames

    Dim gui As New Guid(mem.ProviderUserKey.ToString)Dim name As String = GetName(gui)

    Dim address As New MailAddress(mem.Email, name)

    Dim user As MembershipUser = Membership.GetUser(gui)

    Dim da As New DataSetTableAdapters.MemberInfoTableAdapter

    Dim dt As DataSet.MemberInfoDataTable = da.GetMember(CType(user.ProviderUserKey, Guid))

    Dim mr As DataSet.MemberInfoRow = dt(0)If dt.Rows.Count = 1 AndAlso mr.newsletter = True Then retval.Add(address)

     End If

     Next

    Sunday, February 14, 2010 6:06 PM