serhio
serhio

Reputation: 28586

.NET Windows 7 specific errors

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

WinForm ThreadException

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at System.Windows.Forms.UnsafeNativeMethods.IOleObject.DoVerb(Int32 iVerb, IntPtr lpmsg, IOleClientSite pActiveSite, Int32 lindex, IntPtr hwndParent, COMRECT lprcPosRect) at System.Windows.Forms.AxHost.DoVerb(Int32 verb) at System.Windows.Forms.AxHost.InPlaceActivate()

other one

Exception of type 'System.Windows.Forms.AxHost+InvalidActiveXStateException' 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?

Details

Upvotes: 3

Views: 2665

Answers (4)

SLaks
SLaks

Reputation: 888047

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.

Upvotes: 0

Stefan Steiger
Stefan Steiger

Reputation: 82306

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.

Forms.UnsafeNativeMethods.IOleObject

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.

Upvotes: 5

Erik Funkenbusch
Erik Funkenbusch

Reputation: 93444

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.

Upvotes: 1

SLaks
SLaks

Reputation: 888047

It sounds like you're using an ActiveX control that has compatibility issues with Windows 7.

Upvotes: 2

Related Questions