have problem with this site, can you help please?

guy ranger 0 Reputation points
2025-08-09T09:27:37.7266667+00:00

Erreur du serveur dans l'application '/'.


Le format de la chaîne d'entrée est incorrect.

__Description :__Une exception non gérée s'est produite au moment de l'exécution de la demande Web actuelle. Contrôlez la trace de la pile pour plus d'informations sur l'erreur et son origine dans le code. __Détails de l'exception:__System.FormatException: Le format de la chaîne d'entrée est incorrect. Erreur source:

|Ligne 469 :
Ligne 470 : Dim StrFavoriteGames As String = ""
Ligne 471 : If Session("IdPlayer") <> "" Then
Ligne 472 : StrFavoriteGames = ReturnRecord("SELECT GameId FROM FavoriteGames WHERE IdPlayer=" & Session("IdPlayer"))
Ligne 473 : End If| | -------- | |Ligne 469 : Ligne 470 : Dim StrFavoriteGames As String = "" Ligne 471 : If Session("IdPlayer") <> "" Then Ligne 472 : StrFavoriteGames = ReturnRecord("SELECT GameId FROM FavoriteGames WHERE IdPlayer=" & Session("IdPlayer")) Ligne 473 : End If|

__Fichier source :__C:\www\ludi.com\classmensueltourn.aspx.vb   __Ligne :__471 Trace de la pile:

|[FormatException: Le format de la chaîne d'entrée est incorrect.]
Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat) +201
Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble(String Value, NumberFormatInfo NumberFormat) +68

[InvalidCastException: La conversion de la chaîne "" en type 'Double' n'est pas valide.]
Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble(String Value, NumberFormatInfo NumberFormat) +212
Microsoft.VisualBasic.CompilerServices.Operators.CompareObject2(Object Left, Object Right, Boolean TextCompare) +559
Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectNotEqual(Object Left, Object Right, Boolean TextCompare) +27
classmensueltourn.BuildDropDownList() in C:\www\ludi.com\classmensueltourn.aspx.vb:471
classmensueltourn.Page_Load(Object Sender, EventArgs e) in C:\www\ludi.com\classmensueltourn.aspx.vb:119
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627| | -------- | |[FormatException: Le format de la chaîne d'entrée est incorrect.] Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat) +201 Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble(String Value, NumberFormatInfo NumberFormat) +68 [InvalidCastException: La conversion de la chaîne "" en type 'Double' n'est pas valide.] Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble(String Value, NumberFormatInfo NumberFormat) +212 Microsoft.VisualBasic.CompilerServices.Operators.CompareObject2(Object Left, Object Right, Boolean TextCompare) +559 Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectNotEqual(Object Left, Object Right, Boolean TextCompare) +27 classmensueltourn.BuildDropDownList() in C:\www\ludi.com\classmensueltourn.aspx.vb:471 classmensueltourn.Page_Load(Object Sender, EventArgs e) in C:\www\ludi.com\classmensueltourn.aspx.vb:119 System.Web.UI.Control.OnLoad(EventArgs e) +99 System.Web.UI.Control.LoadRecursive() +50 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627|


Informations sur la version : Version Microsoft .NET Framework :2.0.50727.9066; Version ASP.NET :2.0.50727.9062

Developer technologies | ASP.NET | Other
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Raymond Huynh (WICLOUD CORPORATION) 620 Reputation points Microsoft External Staff
    2025-08-11T07:10:59.1+00:00

    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:

    1. SQL Injection Prevention: Consider using parameterized queries instead of string concatenation for your SQL statement to prevent SQL injection attacks.
    2. Session State Management: Ensure your session state is properly configured in your web.config file.
    3. 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,

    0 comments No comments

  2. guy ranger 0 Reputation points
    2025-08-11T08:30:40.62+00:00

    Hi Raymond,

    Thank you for your time answering my query. I shall try to get adjust following your recommendations,

    Kind regards

    Guy


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.