mrtaikandi
mrtaikandi

Reputation: 6958

Problem with Visual Studio 2008 Debugger

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();
    }
}

Upvotes: 4

Views: 4282

Answers (5)

Yared
Yared

Reputation: 85

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:)

Upvotes: 0

Dour High Arch
Dour High Arch

Reputation: 21722

Known issue with VS2008. A patch is available here.

Upvotes: 5

liammclennan
liammclennan

Reputation: 5368

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.

Upvotes: 0

Eric Nicholson
Eric Nicholson

Reputation: 4123

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.

Upvotes: 0

Neil Barnwell
Neil Barnwell

Reputation: 42165

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.

Upvotes: 2

Related Questions