Hello @guy ranger ,
I can see you're encountering a classic ASP.NET session variable handling issue. The error occurs because your code is trying to compare a session variable that's Nothing
(null) with an empty string, but VB.NET is attempting to convert it to a Double for the comparison operation.
The Problem: In line 471 of your code:
If Session("IdPlayer") <> "" Then
When Session("IdPlayer")
is Nothing
instead of an empty string, VB.NET's type conversion system tries to convert the null value to match the comparison type, which fails.
The Solution: You need to add proper null checking before performing the comparison. Here are a few approaches:
Option 1 (Recommended):
If Not String.IsNullOrEmpty(Session("IdPlayer")) Then
StrFavoriteGames = ReturnRecord("SELECT GameId FROM FavoriteGames WHERE IdPlayer=" & Session("IdPlayer"))
End If
Option 2:
If Session("IdPlayer") IsNot Nothing AndAlso Session("IdPlayer").ToString() <> "" Then
StrFavoriteGames = ReturnRecord("SELECT GameId FROM FavoriteGames WHERE IdPlayer=" & Session("IdPlayer"))
End If
Option 3:
If Session("IdPlayer") IsNot Nothing AndAlso CStr(Session("IdPlayer")) <> "" Then
StrFavoriteGames = ReturnRecord("SELECT GameId FROM FavoriteGames WHERE IdPlayer=" & Session("IdPlayer"))
End If
Additional Recommendations:
- SQL Injection Prevention: Consider using parameterized queries instead of string concatenation for your SQL statement to prevent SQL injection attacks.
- Session State Management: Ensure your session state is properly configured in your web.config file.
- Error Handling: Consider adding try-catch blocks around session variable operations for better error handling.
This type of error is common in older ASP.NET applications (.NET Framework 2.0 as shown in your stack trace), where implicit type conversions can cause unexpected behavior with null values.
I hope this helps resolve your issue. Let me know if you need any clarification or if the error persists after implementing these changes.
Best regards,