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

Asked

Viewed 1,757 times

1

I have an app made on C# to show the menu of my university’s university restaurant, which picks up the information through a XML. The app allows individual consultation of each meal (breakfast, lunch and dinner). It happens that at random times of the day, when one of the queries is requested, an error occurs and the application closes abruptly. Checking with a debug, I noticed the following message: inserir a descrição da imagem aqui

Error

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

I’m using a block now try/catch to see if I can avoid sudden closure, but I haven’t been able to yet.

  • Could someone help me give due treatment to this mistake?

  • 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 like a loop, so that it runs and tries 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 checked now by debug that when it falls in this exception, at the end it shows another error, as in the image below. inserir a descrição da imagem aqui Thank you.

  • Place the error and code where the error is being pointed.

  • Hello you could include the code snippet inserted in the try catch ? , details about your code will help us solve your problem, just edit the question.

  • Possibly an enconding problem? I believe you have q format your ASCII result. Or modify your parser settings to read utf-8.

  • I wanted to at least prevent the application to close abruptly, but even with this catch he is closing.

1 answer

0


To avoid abrupt closure 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 to function XDocument.Parse(e.Result), error can be caused because of text encoding.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.