0

After some months of inactivity, I decided to work with Microsoft Visual Studio (C#) again.

After some clicks on "start debugging" I got windows error (I think svchost.exe has stopped working) and I don't know if this was relevant with what I'm about to say, but I'm not getting any errors when for example I'm calling an array out of bounds.

The program just doesn't execute the code assossiated with the error (I've noticed the array and file I/O problems) but continues to run normally which is driving me crazy because I have to click "start debugging" after I write each line of code just to be sure I'm correct.

So, Debug > Exceptions, it's chaos over there and I haven't touched it before. Any help would be appreciated.

EDIT: I've restarted 3 times my computer and did the Clean and Rebuild just now (the project) and nothing changed.

EDIT2: Sorry if it's confusing, here are some new info:

public partial class frmMain : Form
{
    PictureBox[] pic = new PictureBox[120];
    public frmMain()
    {
        InitializeComponent();
    }
    private void frmMain_Load(object sender, EventArgs e)
        {
            // Creating pictureboxes
            for (int i = 1; i <= 199; i++) //199 instead of 120 or 119 and the rest of the for isn't executed plus no error or warning displayed.
            {
                pic[i] = new PictureBox();

EDIT3: Below is another example. If I try to read a non-existent file without the try-catch sequence, then the whole pic[] matrix is like being unloaded from the memory when the program runs.

    pic[i].Image = Image.FromFile("H:\\My Pictures\\" + i + ".jpg");

EDIT4: Thank you for your time. I tried "Release" instead of "Debug" and the problem was fixed for a while.

When I decided to press "Continue" instead of "Break" on the "OutofRangeException", Windows popped this message: "Windows had to run the program on compatibility mode". Now when I press "start debugging" it's like before...

AchiPapakon
  • 328
  • 5
  • 19
  • What errors do you get? And have you tried to Clean and Rebuild your whole application? – Eugene Podskal Jun 28 '14 at 18:40
  • Have you tried restarting the computer? – Almo Jun 28 '14 at 18:44
  • I've restarted 3 times my computer and did the Clean and Rebuild just now (the project). EDIT: If I do a math error (cast error or something similar) the programs stops, but on the arrays for example, nothing, it just skips the problematic code (for example in a for loop). – AchiPapakon Jun 28 '14 at 18:57
  • There is nowhere near enough information here. What kind of project is it? Do other projects have the same problem? I'm not even sure what your actual problem is, because your description is confusing. – Erik Funkenbusch Jun 28 '14 at 19:04
  • @ErikFunkenbusch I added some more info, please check it. – AchiPapakon Jun 28 '14 at 19:17
  • Why are you still using VS2008? You're 3 major releases and 6 years behind. – Daniel Mann Jun 28 '14 at 19:40
  • @DanielMann Well, I didn't need to upgrade. I just checked the MSDN's list and downloading VS2013 ulimate which it's 32-bit though. Will I have problems? I'm not into multithreding programming yet. – AchiPapakon Jun 28 '14 at 20:04
  • @Achilles - There are many reasons to upgrade, but the biggest reason is that newer versions of Visual Studio are more compatible with newer OS releases. Unless you're still using XP, i'd move to at least VS2010, and preferably at least VS2012/2013. VS2008 is no longer fully supported by Microsoft and is considered "end of life". Mainstram support ended a year ago, and it's now in "Extended Support" which basically just means security patches. – Erik Funkenbusch Jun 28 '14 at 20:23

2 Answers2

0

You have hit a known misfeature in Windows / .Net / C# / Wow64, that happens when Form.Load event handlers throw exceptions.

VS2010 does not show unhandled exception message in a WinForms Application on a 64-bit version of Windows

From Hans Passant's answer:

This is a nasty problem induced by the Windows wow64 emulation layer that allows 32-bit code to run on the 64-bit version of Windows. It swallows exceptions in the code that triggers the Load event. Preventing the debugger from seeing it and stepping in. This is apparently hard to fix, the Windows and DevDiv groups at Microsoft are pointing fingers back and forth. DevDiv can't do anything about it, Windows thinks it is the correct behavior, mysteriously as that sounds. It is only a problem with a debugger attached, your code will bomb as usual without one.

Community
  • 1
  • 1
antiduh
  • 11,853
  • 4
  • 43
  • 66
0

It sounds like you may be dealing with this issue:

Something swallowing up unhandled exceptions?

Basically, when building on 64 bit machines, exceptions are sometimes swallowed.

I believe there may be a hotfix for it, as outlined here:

https://connect.microsoft.com/VisualStudio/feedback/details/357311/silent-exceptions-on-x64-development-machines

Here is the hotfix: http://support.microsoft.com/kb/976038

Otherwise, try setting the target build to x86 rather than x64 or "Any CPU". Also try running in release mode and see if the exceptions occur.

If this is not the problem, then you may need to re-install Visual Studio. If you're using Visual Studio Express, why not upgrade to a more recent version than 2008?

EDIT:

Also, try applying all the service packs and patches to the OS as well. If you're using Windows 7, you should be on SP1 for sure. You should also make sure you are using Visual Studio 2008 SP1 and all patches.

Community
  • 1
  • 1
Erik Funkenbusch
  • 92,674
  • 28
  • 195
  • 291
  • Thank you for your time. I tried "Release" instead of "Debug" and the problem was fixed for a while. When I decided to press "Continue" instead of "Break" on the "OutofRangeException", Windows popped this message: "Windows had to run the program on compatibility mode". Now when I press "start debugging" it's like before... So, it seems I'll be installing Vs2013 32-bit tomorrow (which is free for me). Does it have any major differences with the 64-bit version? – AchiPapakon Jun 28 '14 at 20:13
  • @Achilles - FYI, there is no "32 bit" or "64 bit" version of Visual Studio, it's all one version and can work on both. I mis-stated what I meant by 'releae mode'. I meant running without the debugger (even if it's a debug build). Pressing `F5` or `Start/Continue` runs the debugger. `Ctrl-F5` or `Debug->Start Without Debugging` runs without the debugger – Erik Funkenbusch Jun 28 '14 at 20:17
  • Ctrl-F5 fixed the issue, although this "Start Without Debugging" looks a bit odd to me. Thank you for your help! – AchiPapakon Jun 28 '14 at 20:31