I have a .NET application and a setup fot it. Built using VS 2005.
The development machine is Windows XP SP3.
Once somebody installed it under Windows7. And get the following errors
System.AccessViolationException: Attempted to read or write protected
memory. This is often an indication
that other memory is corrupt.
iVerb, IntPtr lpmsg, IOleClientSite
pActiveSite, Int32 lindex, IntPtr
hwndParent, COMRECT lprcPosRect)
Exception of type
was thrown. Method ‘Disconnect’ cannot
be invoked at this time.
Now, wondered where was the problem, and installed VS 2005 on this Windows7.
Now, the solution compiles and runs without exceptions. I built the setup, and reinstalled the newly built setup on this Win7 machine…
I got the exceptions. Why this?
The applications have no exceptions launched with VS, but throws it when after launching the installed executable…
However, I successfully (without exceptions) tested the installed application on some machines with the OS > Win XP: Windows 7 (x64) and the Windows Server 2008 (x64) …
Studying the logs, I discovered the code that produces the exception:
Panel p = new Panel(); p.Margin = new Padding(0); p.Dock = DockStyle.Fill; p.Controls.Add(display); // 'display' is an ActiveX control instance Logger.LogMessage("before"); this.tableLayoutPanel.Controls.Add(p); // protected memory EXCEPTION Logger.LogMessage("after");
So, I see “before” then
AccessViolationException: Attempted to read or write protected memory... don’t see “after“…
What are the common causes for such an exceptions?
- I use some third party ActiveX in the application;
- Samples (written in C++) using that ActiveX runs well on this machine.
- The solution targets the x86 platform;
- I managed to launch without errors the application on **Windows Server 2008 (x64) and on Windows 7 (x64);
- Tried using ‘Windows XP Compatibility (SP2, SP3)’ mode – the same result (exceptions).
- Tried to install the application in an other folder that
ProgramFiles. I used C:\TestFolder as installation path – the result is the same: AccesViolationException….
Wow, an x84 CPU, never seen one of those ;-))
What you mean is probably x64…
Your Windows XP installation is a 64 Bit one ?
It’s probably a 32/64-Bit conversion issue, and not a Windows 7 issue.
Do you pinvoke your ActiveX dll ?
Is it a 32 bit dll or a 64 bit dll ?
32 bit dll’s won’t run in a 64 bit environment and vice-versa.
If you call it via COM, you might have a chance.
But at least on Linux, the C/C++ datatype long has 8 Bytes in 64 bit mode, while it has 4 Bytes in 32 bit mode.
Try targetting the x86 platform (=32 Bit) in the .NET application.
It sounds like you’re using an ActiveX control that has compatibility issues with Windows 7.
More than likely you’re using an older version of XP that does not have Data Execution Protection. This is enabled by default in Vista and 7, and will cause the exceptions.
You are, most likely, writing to randome pointers, or memory that has already been freed. In other words, you have bugs. Just because it works fine on XP doesn’t mean there’s nothing wrong with it.
Attach the program to a native debugger and check the stack trace.
You may be having issues with a global hook or extension on that machine that interferes with your COM component.