Hi everyone!

I have a c# app, in which I get a FormatException. The problem is that whatever I do to trace it doesn't succeed.

I have tried using breakpoints, try-catch blocks in various parts of the code that I would expect it to occur, putting


in the Main() and still cannot trace it back. Any suggestions? I am out of ideas.



Why don't you try to do it the old fashion way ... comment out suspect code blocks until it doesn't happen anymore :)

What do you mean can't trace it back? I'm guessing you're running the application inside of VS and have the project output set to Debug? Hit CTRL+D, then E. This will bring up the exceptions window. The checkboxes in the right column should all be checked. For trying to catch this exception also check the "Thrown" option for "Common Language runtime Exceptions". To catch unhandled exceptions and generating a bug report for the application before you crash out can be done like this:


using System;
using System.Windows.Forms;

namespace daniweb
  static class Program
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    static void Main()
      Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
      Application.Run(new frmSerkan());

    static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
      System.Text.StringBuilder sb = new System.Text.StringBuilder();
      Exception ex = e.Exception;
      while (ex != null)
        sb.AppendLine("Message: " + ex.Message);
        sb.AppendLine("Source: " + ex.Source);
        sb.AppendLine("Stack: ");
        ex = ex.InnerException;
      //Dont really use a message box. This will be huge!
      if (System.Diagnostics.Debugger.IsAttached)

Simulating it:

private void button13_Click(object sender, EventArgs e)
  throw new NotImplementedException("Crashing!");

Two things to consider:
1) Also make sure you use (code) when ending a code block.
2) Make sure your project has .pdb files in the same directory as the EXE. These are the debugging symbols. They should have the same create date as the assembly.

Yes sorry to mention. Already tried this also

Thanks Sknake. I'll try it (and sorry for code)

commented: A for effort! +9

Next time if you notice that after you post you can go back and hit "Edit Post" under your original post and fix it. You can only edit a post for ~45 minutes after you create it. I think the time as passed already but you can give it a shot :)

Good luck!