2

As of today I can no longer debug any c# code using Visual Studio. If I use the debugger, breakpoints can be hit, but as soon as execution has paused the trouble begins. Pressing Step Into, or Continue will normally generate an AccessViolationException saying the memory is corrupt and kill the current request. If I then run a further web request I will instead get an SEHException (occurred in Unknown Module).

It gets even more odd, in that if the AccessViolationException doesn't trigger, the program counter that shows the next statement jumps randomly. Code is then executed in random order! (until it crashes).

If no breakpoints are hit then the app will run in debug mode just fine (even with the debugger attached).

I am confident it's not a code issue. I can actually reproduce the access violations with a new project and the following code:

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Hello world");
        Console.WriteLine("Access violation"); // This will throw if breakpoint set
    }
}

Have deleted VS cache, deleted .suo, cleaned, and tried safe mode. The one possible suspect is that this is on a Windows 10 preview machine, and there was an update last week. I am not really sure where else to go with this to confirm it, or fix it without reimaging the machine.

AndySavage
  • 1,729
  • 1
  • 20
  • 34
  • here a couple of things u can do- first try enabling breaking on exceptions , second try to change the target platform from 'Any CPU' to 'x86' , third - check this link http://stackoverflow.com/questions/3469368/how-to-handle-accessviolationexception – HappyLee Mar 30 '15 at 21:24
  • No joy unfortunately. My gut feeling is that this is a VS issue rather than a code issue. – AndySavage Mar 31 '15 at 00:44
  • I also get this issue, And then i change the target platform form `Any CPU` to `X64`, It's work for me. – Jeffrey Zhang Mar 31 '15 at 03:16
  • @JeffreyZhang Thanks. I didn't try x64 and bizarrely it works. I needed to tweak a little more, but this got me most the way there. – AndySavage Mar 31 '15 at 15:54

2 Answers2

1

Changing from Any CPU to just x64 resolved this for me on my "Hello World" test project.

To get working on my original project, which was actually a web project, I had to take a few extra steps.

  1. Update all libraries in the project to x64, not just the web project.
  2. Enable 64 bit IIS express in VS2013 Tools > Options > Projects & Solutions > Web Projects > Use 64 Bit IIS ...
  3. Install Internet Information Services Hostable Web Core through Control Panel (Turn Windows Features On or Off). Before I did this I would get an error when launching 64 bit web projects in the form HttpException (0x80004005): Specified argument was out of the range of valid values. Installing HWC fixed it.

Still none the wiser why any of this is happening, but at least I can debug projects again.

AndySavage
  • 1,729
  • 1
  • 20
  • 34
  • Thanks, I just encountered this issue too. I've temporarily resolved if by forcing it to x86, as x64 was incompatible with some references. – Rob H Apr 15 '15 at 14:04
  • I have this a similar debugger problem with web projects in VS2017. I just have to do your step 2 and everything works. For console apps and WPF apps, I have to combile with x64 or I have debugging issues. This is not acceptable. – Jordan Jun 27 '18 at 20:40
0

This exception appeared to start out of nowhere and certainly caused me some headache, but I was able to resolve my issue by doing the following:

  1. Go into the properties of the affected Projects
  2. Go to the Debug Tab
  3. Uncheck "Enable native code debugging"
Bonez024
  • 1,365
  • 1
  • 13
  • 21