0

I get a strange inconsistent server error that is occasionally being raised by a code running when ASP.net web site is loaded.

The exception is a Null reference exception and it happens because somehow the following code (specifically written in VB.net library) generates a null result: "some SQL query".GetHashCode().ToString().

There's no exception happening in the relevant code block and there's nothing else I can see on the server's EventViewer log that can explain this strange behavior.

After reloading the web site the problem disappears.

This code is used for creating a hash key for SQL queries and I cannot have a work around it. Server is Windows Server 2008 R2 with IIS 7.5

  • are you actually calling `GetHashCode` on a string directly, or are you calling it on a variable you've defined? Is it possible that variable is null when you call it? – Alden Nov 05 '13 at 14:53
  • Here's the code block - an implementation of one of our framework's components: `Protected Overrides Function GetHashCodeForGeneratingCacheKey() As String Using oDb As SVCoreDataDbClient = SVCoreDataDbClient.Create() Dim oListSqlParams As SVCoreDataPrezObjectsListPopulatingParams = Me.CreateListPopulatingParams(oDb) Return oListSqlParams.SqlExpression.GetHashCode().ToString() End Using End Function` – user2955798 Nov 05 '13 at 16:57
  • Sorry I was not able to insert new lines in code. Hope it is clear enough. Basically the GetHashCode is called on a string returned value `oListSqlParams.SqlExpression.GetHashCode().ToString()` – user2955798 Nov 05 '13 at 17:04
  • ok well you are getting an error either because `oListSqlParams` is null or `oListSqlParams.SqlExpression` is null. this is not a GetHashCode problem – Alden Nov 06 '13 at 06:16
  • If this was the case I would be getting a null reference exception on this line. However the exception is thrown in a different place where the value returned from the function written above is being used. i.e. the GetHashCode().ToString() returns null – user2955798 Nov 06 '13 at 10:07
  • Are you sure? If GetHashCode returned null, calling .ToString() on it would throw a null reference exception. – Alden Nov 06 '13 at 20:07

0 Answers0