How to debug a try / catch block (android-xamarin development)

0

I am developing in c # an application for android, and I have a try / catch block that I must review, step by step, but when I execute, it does not stop at the breakpoint. Is there any way?

private async void onSaveAsync(object sender, EventArgs e)
{
// recuperar imagen 
Stream x;
byte[] buffer;
Stream reqStream;
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create("ftp://elftp/archivo.png");
try
{
x = await signature.GetImageStreamAsync(SignatureImageFormat.Png);
// this is actually memory-stream so convertible to it
var mstream = (MemoryStream)x;
//Unfortunately above mstream is not valid until you take it as byte array
mstream = new MemoryStream(mstream.ToArray());
//long longitud = mstream.Length;
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential("usuario", "password");
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = true;
buffer = BitConverter.GetBytes(mstream.Length);
mstream.Read(buffer, 0, buffer.Length);
mstream.Close();
reqStream = request.GetRequestStream();
reqStream.Write(buffer, 0, buffer.Length);
reqStream.Flush();
reqStream.Close();
}
catch (DirectoryNotFoundException dirEx)
{
// Let the user know that the directory did not exist.
Console.WriteLine("Directory not found: " + dirEx.Message);
} 
}

The problem with this code is that the image that is recorded in the FTP is not the signaturepad image, but something like a small icon, which contains nothing. There is a problem in the recovery of the image as such, and the time to prepare it to upload it to FTP.

Solved !!! It was a variable type theme .. I had to use the typo byte.

Thanks

    
asked by Jordi Maicas Peña 24.02.2018 в 02:56
source

1 answer

2

In the code that you have put, I see two things. The first the Console.WriteLine only works in console type projects, in a visual project (wpf, xamarin, etc ...) you have to put Debug.WriteLine

The second one, you have a relatively large block of code and the only exception you capture is the DirectoryNotFoundException type, that is, you will only enter the catch if within that whole block it fails to find a directory . If you want to see any other error you can do it like this:

catch (DirectoryNotFoundException dirEx)
{
    // Let the user know that the directory did not exist.
    Debug.WriteLine("Directory not found: " + dirEx.Message);
} 
catch (Exception ex)
{
    Debug.WriteLine("Generic error: " + ex.Message);
} 
    
answered by 05.03.2018 в 12:00