I have an application that is crashing with no error message and it is doing some really strange things.
It is a Pocket PC application written using C# for the .NET Compact Framework
Here is a code sample
foreach(XmlNode nLabel in nlstLabel)
Label1 = (string)selectSingleNode(nUDFLabel, "l_1");
Label2 = (string)selectSingleNode(nUDFLabel, "l_2");
Label3 = (string)selectSingleNode(nUDFLabel, "l_3");
Label4 = (string)selectSingleNode(nUDFLabel, "l_4");
Label5 = (string)selectSingleNode(nUDFLabel, "l_5");
/* NOTE THIS SPACE 11 */
/* NOTE THIS SPACE 22 */
SqlCeCommand sqlUDF = ssceconn.CreateCommand();
sqlUDF.CommandText = insertStatement;
I knew it was crashing around here because after checking the database I realized the the sqlUDF command was never executing because the table was empty.
The strage behavior comes in here. Since I was getting no error message or Exception (which is caught) I started putting in MessageBox.Show(); statements to see which line was causing the problem. When I put these statements in the application worked fine and all database table had proper data. A friend said this used to happen to him in VB and its better to print to a file because MsgBox can change the way an application executes code. So I printed to a file and the application still worked. Even if I just open a file stream at the begining of this whole method and dont print anything to the file everything still works.
So I started working backwards. When I put in a MessageBox.Show() in the space marked /* NOT THIS SPACE 22 */ The message never appeared and the application crashed. SO I thought, it must be happening in the for each loop. So I put a MessageBox.Show() in the space marked /* NOT THIS SPACE 11 */ and when I ran the application I saw the message appear and the application never crashed. Since this for each loop always only has one iteration I assume it must be crashing when it reads the for each statement for the last time. But why is it not crashing all the time? How come opening a file or showing a message box before that line of code causes the application to work properly? Also, if I step through the code in Debug mode, debuging from the device, the application runs fine.
Another note, this application was tested and released and has been working for the past 2 years. I recently made an update to some code that has nothing to do with this code and when I recompiled It started crashing in this method. I even viewed the differences between the files before and after I made the update and no changes were made to that code.
So I guess my questions are: Is it possible to find an error message somewhere in the system (Windows Mobile)? Has anyone experiences this type of strange behavior before? Do you have any suggestions on how to resolve this problem?
Any suggestions would be greatly appricated. I am heading into day 4 trying to fix this problem and I'm losing hope. I could open a file stream and that should fix the problem but that does not seem like a good solution to me. As I leave you Im going to see if any compile paramters were changed, even though I never touched them.