Exception Error "'', hexadecimal value 0x1F, is an invalid character. Line 1, position 1 "

1

I have an application made with C# to display the menu of my university's university restaurant, which picks up the information by means of XML . The application allows the individual consultation of each meal (breakfast, lunch and dinner). It happens that at random times of the day, when any of the queries are requested, an error occurs and the application closes abruptly. Checking with debug , I noticed the following message appears:

Error

  

"'', hexadecimal value 0x1F, is an invalid character. Line 1,   position 1 ".

I am now using a block try/catch to see if I can avoid the abrupt closing but I have not succeeded yet.

  • Could anyone help me give due treatment to this error?

  • How can I solve this problem, at least to avoid abrupt closure of the application?

My try / catch block for now did just that, to try to prevent it from closing. The LoadDataHoje () method is looping so that it executes and attempts to access the information.

catch (System.ArgumentException erro)  
            {  
                LoadDataHoje();  
                contador++;  
                if(contador == 5)  
                {  
                    throw new ArgumentException();  
                    MessageBox.Show("O servidor está retornando um erro, tente novamente daqui a pouco :/","Erro no servidor", MessageBoxButton.OK);  
                    this.NavigationService.Navigate(new Uri("/Src/Pages/MainPage.xaml", UriKind.Relative));  
                }  
            }  

I have now checked out the debug that when it falls into this exception, at the end it shows another error, as in the image below. Thank you.

    
asked by anonymous 06.04.2016 / 02:55

1 answer

0

To avoid abrupt closing change your code like this:

try
{
     ...
}
catch (System.ArgumentException erro)
{
    LoadDataHoje();
    contador++;
    if (contador == 5)
    {
        // throw new ArgumentException(); Remova isso!!!-> Esse cara está fechando a aplicação.
        MessageBox.Show("O servidor está retornando um erro, tente novamente daqui a pouco :/", "Erro no servidor", MessageBoxButton.OK);
        this.NavigationService.Navigate(new Uri("/Src/Pages/MainPage.xaml", UriKind.Relative));
    }
}
catch(Exception ex)//Por precausão
{
     ...
}

As for the XDocument.Parse(e.Result) function, the error can be caused by the encoding of the text.

    
09.04.2016 / 05:40