views:

1176

answers:

5

Hi all.

I have a weird problem with Visual Studio 2008 in just one of my projects. When I set a break point on a line of code, it gets hit alright, but when I try to 'step over,' or whatever else that is supposed to pass over that break point and stop on the next line, the code gets executed and continues as if I hit F5. This occurs even if I have another break point on the line just after this one, and strangely, the second break point is ignored (sometimes).

Anybody, any ideas?

UPDATED

Here is a sample code. But it seems that anywhere that I have a try...catch block in which an exception is thrown, I have this problem.

In the following code sample "return (T)bFormatter.Deserialize(mStream)" throws an exception.

public static T LoadEncryptedObject<T>(string location) where T : class
{
    if( string.IsNullOrEmpty(location) || !System.IO.File.Exists(location) )
        return default(T);

    System.IO.FileStream fs = null;
    try
    {
        fs = new System.IO.FileStream(location, System.IO.FileMode.Open,
            System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite);
        BinaryFormatter bFormatter = new BinaryFormatter();

        byte[] encryptedBytes = new byte[fs.Length];
        fs.Read(encryptedBytes, 0, encryptedBytes.Length);
        MemoryStream mStream = new MemoryStream(Cryptography.Decrypt(encryptedBytes));

        return (T)bFormatter.Deserialize(mStream);
    }
    catch( SerializationException sx )
    {
        System.Diagnostics.Debug.WriteLine(sx.Message);
        return default(T);
    }
    finally
    {
        if( fs != null )
            fs.Close();
    }
}
+2  A: 

Often this can be due to an uncaught exception. Try catching all exceptions in your IDE.

On the menu bar click Debug->Exceptions... and check the "Thrown" checkbox for Common Language Runtime Exceptions.

Neil Barnwell
The problem is in fact related to exceptions, but the thing is, I caught the thrown exception using a try...catch block, but lines of code are still ignored.
Mohammadreza
This will be hard to track, then. As balexandre said in a comment to your question, try uploading a screencast using Jing http://www.jingproject.com/.
Neil Barnwell
In fact, can you post the code?
Neil Barnwell
A: 

Is Cryptography.Decrypt a wrapper around the COM Encryption Provider framework? Anytime you evaluate something that's implemented in COM you'll get some unusual threading issues that sound similar to what you've described.

A lot of times what helps me is closing the watch, autos, and locals windows and then being very careful not to mouse-hover over anything to avoid triggering debugger evaluation.

Eric Nicholson
A: 

My suspicion is that while you are paused on the breakpoint an exception occurs on another thread. When you step-over the exception takes priority and the debugger jumps over to that thread.

The simple solution is to ensure that you are only debugging one thread.

liammclennan
+4  A: 

Known issue with VS2008. A patch is available here.

Dour High Arch
A: 

I had the same problem. It was because my application was using another application i.e. Dbmonitor to trace database events but I wasn't running the Dbmonitor while debugging. So check if u add any code to use any third party application. This might Help u:)

Yared