Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1028167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:20:45+00:00 2026-05-16T12:20:45+00:00

I’ve got an ASP.Net application, which starts throwing NUllReferenceExceptions, after a long period of

  • 0

I’ve got an ASP.Net application, which starts throwing NUllReferenceExceptions, after a long period of running. The code in question is used early on in each individual session, where we’re trying to establish some kind of referrer information. The thing is, I can’t fathom out what can throw this exception.

The method in question (topmost in the stack trace) is:

Private Function ResolveReferrer(ByVal wrRequest As HttpRequest) As Referral

  '1) If we don't find a domain, try and get a match on any query strings
  If wrRequest.QueryString.Count > 0 Then
    For Each item As Referral In Me
      For Each sKey As String In wrRequest.QueryString.Keys
        If Not sKey Is Nothing AndAlso item.Names.Contains(sKey.ToLower) Then
          Return item
        End If
      Next sKey
    Next item
  End If


  Dim strSubDomain As String = Utility.RequestSubDomain(wrRequest.Url)
  '2) If we don't find one on the domain, see if we can find the domain in query string
  If Not wrRequest.QueryString.Item("domain") Is Nothing Then
    strSubDomain = wrRequest.QueryString.Item("domain")

    strSubDomain = HttpUtility.UrlDecode(strSubDomain)

    ' OK found a "domain" query string, so make up a referrer object to return
    ' ... just use the domain we've found for all the parameters
    Dim oRef As New Referral(strSubDomain, strSubDomain, strSubDomain)
    Return oref
  End If


  '3) If no query string of "domain", then see if the referring field is presented by the browser
  If Not wrRequest.UrlReferrer Is Nothing Then
    Dim sURL As String = wrRequest.UrlReferrer.ToString
    strSubDomain = Utility.RequestSubDomain(wrRequest.UrlReferrer)

    Dim oRef As New Referral(sURL, sURL, strSubDomain)
    Return oRef
  End If


  '4) See if we can find the domain defined in the web.config
  For Each item As Referral In Me

    ' See if we can find a referrer from the domain name
    If String.Compare(strSubDomain, item.FromDomain, False) = 0 Then
      Return item
    End If

  Next item


  '5) If we still can't find one, make one up with a value of "Unknown"
  Return New Referral("Unknown", "Unknown", "Unknown", "Unknown")
End Function

The class that this is a part of inherits from ArrayList. I’ve checked, and the only things added to this ArrayList are instances of the Referral class (which has multiple constructors, all simple).

What we do know is that, we can have a request that comes in with no referrer information, and it causes the exception to be thrown. At the same time, if a request with a referrer comes in, it works fine. In neither case is anything passed in the query string (so I think you can skip down to the ‘3 comment.

So, my question is, what in this method can cause a NullReferenceException to be thrown? If you need additional snippets added, or class definitions, just shout.

Utility.RequestSubDomain has reasonable complexity, so I doubt that it’s being inlined and removed from the stack trace. And it’s top is:

Public Shared Function RequestSubDomain(ByVal uri As System.Uri) As String
    If uri Is Nothing Then
        Return ""
    End If

Any help, or suggestions for finding more information would be appreciated. It’s obviously (as with so many problems) only happening in production, so I don’t want to switch on debugging.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T12:20:46+00:00Added an answer on May 16, 2026 at 12:20 pm

    I took a good hard look and the only two things that come to mind that seem like the most likely are:

    • wrRequest could be null.
    • The ArrayList could have null values in it resulting in an enumerator that returns null values.

    If it were me I would first focus my attention on this section. Is there any way possible that the Me.GetEnumerator will return an enumerator with one of the items having a null value?

    For Each item As Referral In Me 
      item.Names ' Can item be null here causing the exception on the getter of Names?
    Next item 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.