none
System.AccessViolationException when calling a Foxpro in-process automation server from C# RRS feed

  • Question

  • We have a .Net 2.0 application that loads a Foxpro in-process automation server (Unmanaged DLL).

    This works fine on almost all of the machines on which it is installed.

    However, on some Window 2003 Server and all Vista machines, it fails with the following error when we call the first entry point:

    System.AccessViolationException: Attempted to read or write protected memory.  This is often an indication that other memory is corrupt.
    at mat_dll.mat_dllClass.FromSAMAuthorization(string cUser, String cPwd, String Vendor)
    at TestDllLoad.Form1.button_Click(Object sender, EventArgs e)

    We have a VB6 application which uses the same unmanaged DLL and it works. However, when our C# .Net 2.0 application instantiates the unmanaged DLL object, it generates the above error on the first call.

    We think there may be some security feature that restricts execution of unmanaged code.

    We used the .NET framework 2.0 configuration administrative tool to verify that the application and the interop has unrestricted permissions granted.

    We executed the Code Access Security Policy >> Evaluate Assembly function to confirm this.

    If you have any information that will help us solve this it would be greatly appreciated.


     

    Wednesday, June 4, 2008 2:39 PM

Answers

  • Security doesn't cause AccessViolation exceptions.  Unless you are swallowing an exception that is trying to tell you something is wrong.  Run it in the debugger and keep an eye on "first chance exception" messages in the Output window.
    Hans Passant.
    • Marked as answer by Bruno Yu Tuesday, June 10, 2008 6:04 AM
    Wednesday, June 4, 2008 2:54 PM
    Moderator

All replies

  • Security doesn't cause AccessViolation exceptions.  Unless you are swallowing an exception that is trying to tell you something is wrong.  Run it in the debugger and keep an eye on "first chance exception" messages in the Output window.
    Hans Passant.
    • Marked as answer by Bruno Yu Tuesday, June 10, 2008 6:04 AM
    Wednesday, June 4, 2008 2:54 PM
    Moderator
  • Thanks Hans,

    I will try what you suggested.

    It seems to point to something related to using .net 2.0 since we can call it from a non- .net VB6 program.

    The other interesting thing is that it works on some Windows 2003 Server SP2 machines.

    Wednesday, June 4, 2008 6:02 PM
  • Another bit of information. If we build the application on a vista machine it runs fine on the Vista machine. 

    If we copy the exe, interop and dll from an XP build environment to the same visit machine we get the error.

    Also Hans, I attached the debugger to the application and the First Chance Exception was the AccessViolation nothing more was given.

    Wednesday, June 4, 2008 7:39 PM
  • Then you're SOL, that FoxPro component just doesn't like the execution environment for some reason.  You'll have to contact Microsoft CSS for support.
    Hans Passant.
    • Proposed as answer by Bruno Yu Tuesday, June 10, 2008 6:04 AM
    Wednesday, June 4, 2008 8:00 PM
    Moderator
  • I agree. We are SOL. We are planning on rewriting the FoxPro component in C# but wanted to get this working in the meantime. 

    We did determine that when we instantiate the component it successfully calls the components' Init routine but even though the reference to the component is not null any access to the components methods throw an AccessViolationException. We verified this by running the program in the debugger on the Windows 2003 Server machine on which we were having the problem. When you view the component's reference in the debugger quick watch all of the entry points show AccessViolationException. 

    Thanks for your input,

    RiverSoft
    Thursday, June 5, 2008 7:36 PM