Blog Entries

DEP, .NET, Windows and Accpac

Dec 8

Written by:
12/8/2009 12:00 AM  RssIcon

Last year after we installed Vista on our development machines, we came across a problem with .Net programs and Accpac.

We’ve been writing some of our custom Accpac programs in .Net and calling the Accpac COM API to interface with Accpac ERP. But when these .Net programs were run on our Vista machines they would crash. But only when using one of the Accpac COM API’s that would pop open a window. Calling a Finder through the API or doing a ShowErrors call would instantly crash the program. Everytime.

After doing a LOT OF investigating, we discovered that the problem was related to DEP (Data Execution Protection). If we disabled DEP on our workstations, the problem would go away.

With some more digging, we came up with a theory that fits pretty well. Turns out the ATL library had some problems with DEP (up to and including V7.1). They do some kind of runtime code creation for thunking that makes DEP think the program is trying to run data. And then DEP causes the program to crash. Guess who uses ATL components in their COM API? Correct! Accpac! Everytime we used the COM API that opened a window of some kind, an ATL component was called and BAM! Down it goes.

The other part of the puzzle is related to Visual Studio 2008. Turns out that the NXCOMPAT switch is turned on by default for executables that VS2008 builds. This switch tells DEP that the program is compatible and DEP should check everthing. (and crash bad behaviour).

Now that we knew what was going on, what were our options?

  • We could turn DEP completely off
    • use: bcdedit.exe/set {current} nx AlwaysOff
    • (not recommended)
  • Set the NXCOMPAT file on our executables
    • editbin.exe /NXCOMPAT:NO

So, being the lazy programmers we are, what did we do? Of course, we just turned DEP off and forgot about it. Problem solved right?

Guess what happened when we rebuilt our machines to install Windows 7? Yup, our problem was back. Only we had forgotten what caused it and it took a few hours of investigation to figure it out and remember what we did. (even though we had documented it in our office knowledge base…geesh!). So, this time we decided to do it right and a the NXCOMPAT:NO setting to our builds.

Now the problem is fixed and should stay fixed.

Your name:
Gravatar Preview
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Security Code
Enter the code shown above in the box below
Add Comment   Cancel 



Recent Entries

How we built Murphy's booking system
Murphy's web store goes Live
Problem with new Desktop Icon Protocol
Debugging .NET Accpac Addons
Registrationless COM
Moving from MS to Open Source
Board of Examiners Christmas Lunch
Sage ERP Accpac 5.6 has been released
DEP, .NET, Windows and Accpac