AccessViolationException with a webbrowser in a windows form-Collection of common programming errors
I have written a basic Windows Form app in C# that has an embedded web browser control. I am navigating to a page to view a camera’s feed. The application works fine on Windows XP, but not on Vista.
On Vista, I get a AccessViolationException. This seems to be related to Data Execution Prevention.
The article at http://jtstroup.net/CommentView,guid,3fa30293-a3a4-4a1c-a612-058e751ad151.aspx has a couple solutions. The fix at the bottom of the page, editbin.exe /NXCOMPAT:NO YourProgram.exe from a Visual Studio Command Prompt works just fine.
However, what I’d like is to use the post build event method, by adding the following as suggested:
REM Mark project as DEP Noncompliant call “$(DevEnvDir)….\VC\bin\vcvars32.bat” call “$(DevEnvDir)….\VC\bin\editbin.exe” /NXCOMPAT:NO “$(TargetPath)”
However, this doesn’t work when I try to run the program through the debugger (i.e. I get the same exception).
Any ideas?
-
According to this article:
Because It was observed in a Setup project with Visual Studio 2008 that the Add Project Output source path Points to c:\App\OBJ*.exePost Build Event would update c:\app\BIN*.exe and not the OBJ.
Manually add the build in setup and deployment Project Create New Setup Project | Add File | select Build EXE which is under Bin Folder
-
Question. The vista version you are trying. Is it 64bit? If so, compile the code to x86 only and try.
-
It’s not 64 bit.
Turning off the Visual Studio Hosting Process worked for debugging.
However, upon creating a setup project which uses the primary output of my sample project, and installing the project from the Visual Studio menu, I get the same error. So perhaps the post build event isn’t being applied, or something in the setup project is overriding that setting?
Any ideas? I’m unsure of whether the post build event is applied in setup projects.
-
Does the page you are viewing contain a java applet ? I’ve encountered this exact issue and traced it to that. It’s due to the WebBrowser Control using Microsoft’s JVM which is now not supported I believe.
-
I had to add another line to my post build event
call “$(DevEnvDir)..\tools\vsvars32.bat” editbin.exe /NXCOMPAT:NO “$(TargetPath)” editbin.exe /NXCOMPAT:NO “$(ProjectDir)obj\$(ConfigurationName)\$(TargetFileName)”
this edits the exe in the obj folder. It seems that is what my Deployment project uses.
I got the idea from here. Microsoft Forum