我有一个ASP.NET应用程序,在长时间运行之后,它开始抛出NullReferenceExceptions。所讨论的代码在每个单独会话的早期使用,我们试图在其中建立某种引用者信息。问题是,我不知道什么可以抛出这个例外。
所讨论的方法(堆栈跟踪中的最顶层)是:
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
这是继承自ArrayList的一部分的类。我已经检查过了,添加到这个arraylist中的只有引用类的实例(它有多个构造函数,都很简单)。
我们所知道的是,我们可以有一个没有引用信息的请求,它会导致抛出异常。同时,如果一个有推荐人的请求出现,它就可以正常工作。在这两种情况下,查询字符串中都没有传递任何内容(所以我认为您可以跳到'3注释)。
所以,我的问题是,这个方法中的什么可以导致抛出NullReferenceException?如果您需要添加额外的代码片段或类定义,只需大喊。
utility.requestSubDomain具有合理的复杂性,因此我怀疑它是否被内联并从堆栈跟踪中删除。最重要的是:
Public Shared Function RequestSubDomain(ByVal uri As System.Uri) As String
If uri Is Nothing Then
Return ""
End If
如有任何帮助或建议,寻求更多信息将不胜感激。它是
明显地
(和许多问题一样)只在生产中发生,所以我不想打开调试。