Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.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

  • 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....
like image 857
serhio Avatar asked May 18 '26 04:05

serhio


1 Answers

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.

like image 180
Stefan Steiger Avatar answered May 19 '26 17:05

Stefan Steiger