HighTechTalks DotNet Forums  

System.AccessViolation when opening Modal VB6 Form from Hosted VB6 ActiveX control inside .NET WinForms application

Dotnet Framework (Interop) microsoft.public.dotnet.framework.interop


Discuss System.AccessViolation when opening Modal VB6 Form from Hosted VB6 ActiveX control inside .NET WinForms application in the Dotnet Framework (Interop) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Willy Van den Driessche
 
Posts: n/a

Default System.AccessViolation when opening Modal VB6 Form from Hosted VB6 ActiveX control inside .NET WinForms application - 01-21-2010 , 03:36 PM






Hi,
i have a rather simple question with a large background. We have a huge existing VB6 application consisting of 100+ VB6 com components. We are rewriting this app in .NET. Since there is more than 30 man years in the existing aplication, we are doing this step by step. In the meantime, the old components are hosted in the new .NET Winforms application. They all behave in a similar way : they show a list of items and have a toolbar on top of it. The grid and the toolbar are activeX controls, hosted on the main screen of the .NET application. All components expose a COM class with a common interface. These classes are instantiated by the .NET application and passed to the grid. The grid displays fine and behaves as planned. However, when the popup menu of the grid is invoked to display a modal (COM) form. Here however things go wrong. On Windows XP the application occasionally hangs. On Windows Vista the application crashes 95% of the time with the exception :


---> System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageA(MSG& msg)
at System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.RunDialog(Form form)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog()

I can explain for 3 more pages but that's not the idea. We have tried everything. *any* idea is welcome.




__________ Informatie van ESET NOD32 Antivirus, versie van database viruskenmerken 4794 (20100121) __________

Het bericht is gecontroleerd door ESET NOD32 Antivirus.

http://www.eset.com

Reply With Quote
  #2  
Old   
Fábio Chicout
 
Posts: n/a

Default RE: System.AccessViolation when opening Modal VB6 Form from Hosted VB6 - 01-21-2010 , 05:19 PM






Hi Willy,

Well, I've got this message when my parameters weren't decorated (atributes,
out, in modifiers) correctly.

"Willy Van den Driessche" wrote:

Quote:
Hi,
i have a rather simple question with a large background. We have a huge
existing VB6 application consisting of 100+ VB6 com components. We are
rewriting this app in .NET. Since there is more than 30 man years in the
existing aplication, we are doing this step by step. In the meantime, the
old components are hosted in the new .NET Winforms application. They all
behave in a similar way : they show a list of items and have a toolbar on
top of it. The grid and the toolbar are activeX controls, hosted on the
main screen of the .NET application. All components expose a COM class
with a common interface. These classes are instantiated by the .NET
application and passed to the grid. The grid displays fine and behaves as
planned. However, when the popup menu of the grid is invoked to display a
modal (COM) form. Here however things go wrong. On Windows XP the
application occasionally hangs. On Windows Vista the application crashes
95% of the time with the exception :


---> System.AccessViolationException: Attempted to read or write protected
memory. This is often an indication that other memory is corrupt.
at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageA(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.Uns
afeNativeMethods.IMsoComponentManager.FPushMessage Loop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.RunDialog(Form form)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog()

I can explain for 3 more pages but that's not the idea. We have tried
everything. *any* idea is welcome.




__________ Informatie van ESET NOD32 Antivirus, versie van database
viruskenmerken 4794 (20100121) __________

Het bericht is gecontroleerd door ESET NOD32 Antivirus.

http://www.eset.com


Reply With Quote
  #3  
Old   
Willy Van den Driessche
 
Posts: n/a

Default Re: System.AccessViolation when opening Modal VB6 Form from Hosted VB6 - 01-21-2010 , 05:29 PM



Thanks for the reply.

My parameters ought to be decorated correctly since they are all generated
using impLib and aximp.
But maybe these tools made a mistake. I'll check on them again.



"Fábio Chicout" <FbioChicout (AT) discussions (DOT) microsoft.com> wrote

Quote:
Hi Willy,

Well, I've got this message when my parameters weren't decorated
(atributes,
out, in modifiers) correctly.

"Willy Van den Driessche" wrote:

Hi,
i have a rather simple question with a large background. We have a huge
existing VB6 application consisting of 100+ VB6 com components. We are
rewriting this app in .NET. Since there is more than 30 man years in the
existing aplication, we are doing this step by step. In the meantime,
the
old components are hosted in the new .NET Winforms application. They all
behave in a similar way : they show a list of items and have a toolbar on
top of it. The grid and the toolbar are activeX controls, hosted on the
main screen of the .NET application. All components expose a COM class
with a common interface. These classes are instantiated by the .NET
application and passed to the grid. The grid displays fine and behaves
as
planned. However, when the popup menu of the grid is invoked to display
a
modal (COM) form. Here however things go wrong. On Windows XP the
application occasionally hangs. On Windows Vista the application crashes
95% of the time with the exception :


---> System.AccessViolationException: Attempted to read or write
protected
memory. This is often an indication that other memory is corrupt.
at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageA(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.Uns
afeNativeMethods.IMsoComponentManager.FPushMessage Loop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.RunDialog(Form form)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog()

I can explain for 3 more pages but that's not the idea. We have tried
everything. *any* idea is welcome.




__________ Informatie van ESET NOD32 Antivirus, versie van database
viruskenmerken 4794 (20100121) __________

Het bericht is gecontroleerd door ESET NOD32 Antivirus.

http://www.eset.com



__________ Informatie van ESET NOD32 Antivirus, versie van database
viruskenmerken 4794 (20100121) __________

Het bericht is gecontroleerd door ESET NOD32 Antivirus.

http://www.eset.com




__________ Informatie van ESET NOD32 Antivirus, versie van database viruskenmerken 4794 (20100121) __________

Het bericht is gecontroleerd door ESET NOD32 Antivirus.

http://www.eset.com

Reply With Quote
  #4  
Old   
Family Tree Mike
 
Posts: n/a

Default Re: System.AccessViolation when opening Modal VB6 Form from HostedVB6 ActiveX control inside .NET WinForms application - 01-21-2010 , 06:41 PM



On 1/21/2010 4:36 PM, Willy Van den Driessche wrote:
Quote:
Hi,
i have a rather simple question with a large background. We have a huge
existing VB6 application consisting of 100+ VB6 com components. We are
rewriting this app in .NET. Since there is more than 30 man years in the
existing aplication, we are doing this step by step. In the meantime,
the old components are hosted in the new .NET Winforms application. They
all behave in a similar way : they show a list of items and have a
toolbar on top of it. The grid and the toolbar are activeX controls,
hosted on the main screen of the .NET application. All components expose
a COM class with a common interface. These classes are instantiated by
the .NET application and passed to the grid. The grid displays fine and
behaves as planned. However, when the popup menu of the grid is invoked
to display a modal (COM) form. Here however things go wrong. On Windows
XP the application occasionally hangs. On Windows Vista the application
crashes 95% of the time with the exception :
---> System.AccessViolationException: Attempted to read or write
protected memory. This is often an indication that other memory is corrupt.
at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageA(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.RunDialog(Form form)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog()
I can explain for 3 more pages but that's not the idea. We have tried
everything. *any* idea is welcome.


__________ Informatie van ESET NOD32 Antivirus, versie van database
viruskenmerken 4794 (20100121) __________

Het bericht is gecontroleerd door ESET NOD32 Antivirus.

http://www.eset.com
I always suspect one of two things in these types of errors:

1. The COM components are built for 32 bit, and you are running 64 bit.
2. Permissions somewhere in the registry finding the components.

You don't say whether the errors happen occasionally/90% on single
machines, or those ratios are "of machines tested". I would build for
x86 (32 bit) first, and retest, since that is the easiest diagnosis.
For the permissions issue, setup a test account with elevated settings
to diagnose.

--
Mike

Reply With Quote
  #5  
Old   
Willy Van den Driessche
 
Posts: n/a

Default Re: System.AccessViolation when opening Modal VB6 Form from Hosted VB6 ActiveX control inside .NET WinForms application - 01-21-2010 , 06:49 PM



Thanks for your reply.

Unfortunately, I cannot see why this would be the case
1) The components are built and run on 32 bit
2) The same components run fine on the exact same machine when run from the
original COM-only host application

"Family Tree Mike" <FamilyTreeMike (AT) ThisOldHouse (DOT) com> wrote

Quote:
On 1/21/2010 4:36 PM, Willy Van den Driessche wrote:
Hi,
i have a rather simple question with a large background. We have a huge
existing VB6 application consisting of 100+ VB6 com components. We are
rewriting this app in .NET. Since there is more than 30 man years in the
existing aplication, we are doing this step by step. In the meantime,
the old components are hosted in the new .NET Winforms application. They
all behave in a similar way : they show a list of items and have a
toolbar on top of it. The grid and the toolbar are activeX controls,
hosted on the main screen of the .NET application. All components expose
a COM class with a common interface. These classes are instantiated by
the .NET application and passed to the grid. The grid displays fine and
behaves as planned. However, when the popup menu of the grid is invoked
to display a modal (COM) form. Here however things go wrong. On Windows
XP the application occasionally hangs. On Windows Vista the application
crashes 95% of the time with the exception :
---> System.AccessViolationException: Attempted to read or write
protected memory. This is often an indication that other memory is
corrupt.
at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageA(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.RunDialog(Form form)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog()
I can explain for 3 more pages but that's not the idea. We have tried
everything. *any* idea is welcome.


__________ Informatie van ESET NOD32 Antivirus, versie van database
viruskenmerken 4794 (20100121) __________

Het bericht is gecontroleerd door ESET NOD32 Antivirus.

http://www.eset.com

I always suspect one of two things in these types of errors:

1. The COM components are built for 32 bit, and you are running 64 bit.
2. Permissions somewhere in the registry finding the components.

You don't say whether the errors happen occasionally/90% on single
machines, or those ratios are "of machines tested". I would build for x86
(32 bit) first, and retest, since that is the easiest diagnosis. For the
permissions issue, setup a test account with elevated settings to
diagnose.

--
Mike

__________ Informatie van ESET NOD32 Antivirus, versie van database
viruskenmerken 4795 (20100121) __________

Het bericht is gecontroleerd door ESET NOD32 Antivirus.

http://www.eset.com




__________ Informatie van ESET NOD32 Antivirus, versie van database viruskenmerken 4795 (20100121) __________

Het bericht is gecontroleerd door ESET NOD32 Antivirus.

http://www.eset.com

Reply With Quote
  #6  
Old   
Family Tree Mike
 
Posts: n/a

Default Re: System.AccessViolation when opening Modal VB6 Form from HostedVB6 ActiveX control inside .NET WinForms application - 01-21-2010 , 07:32 PM



On 1/21/2010 7:49 PM, Willy Van den Driessche wrote:
Quote:
Thanks for your reply.

Unfortunately, I cannot see why this would be the case
1) The components are built and run on 32 bit
2) The same components run fine on the exact same machine when run from
the original COM-only host application

Sorry, but I may not have explained my point well.

If the .Net container app is built with "Any CPU", and run on a 64 bit
OS, then the COM components are running in 64 bit mode. This can cause
problems such as what you have reported. I suspect your COM-only host
is built for 32 bit mode.

--
Mike

Reply With Quote
  #7  
Old   
Willy Van den Driessche
 
Posts: n/a

Default Re: System.AccessViolation when opening Modal VB6 Form from Hosted VB6 ActiveX control inside .NET WinForms application - 01-22-2010 , 02:00 AM



I was just saying that we are not ready yet for 64-bit problems (we have
enough in the 32-bit world).
We are running, compiling and testing on 32-bit OS.

"Family Tree Mike" <FamilyTreeMike (AT) ThisOldHouse (DOT) com> wrote

Quote:
On 1/21/2010 7:49 PM, Willy Van den Driessche wrote:
Thanks for your reply.

Unfortunately, I cannot see why this would be the case
1) The components are built and run on 32 bit
2) The same components run fine on the exact same machine when run from
the original COM-only host application


Sorry, but I may not have explained my point well.

If the .Net container app is built with "Any CPU", and run on a 64 bit OS,
then the COM components are running in 64 bit mode. This can cause
problems such as what you have reported. I suspect your COM-only host is
built for 32 bit mode.

--
Mike

__________ Informatie van ESET NOD32 Antivirus, versie van database
viruskenmerken 4795 (20100121) __________

Het bericht is gecontroleerd door ESET NOD32 Antivirus.

http://www.eset.com




__________ Informatie van ESET NOD32 Antivirus, versie van database viruskenmerken 4795 (20100121) __________

Het bericht is gecontroleerd door ESET NOD32 Antivirus.

http://www.eset.com

Reply With Quote
  #8  
Old   
Christian Fröschlin
 
Posts: n/a

Default Re: System.AccessViolation when opening Modal VB6 Form from HostedVB6 ActiveX control inside .NET WinForms application - 01-22-2010 , 02:48 AM



Willy Van den Driessche wrote:

Quote:
grid. The grid displays fine and behaves as planned. However, when the
popup menu of the grid is invoked to display a modal (COM) form. Here
however things go wrong.
Do you have access to the source code for the grid and modal form?
If so I'd try to narrow down the problem by removing controls and
code from the form to see if and when the issue goes away.

Reply With Quote
  #9  
Old   
Willy Van den Driessche
 
Posts: n/a

Default Re: System.AccessViolation when opening Modal VB6 Form from Hosted VB6 ActiveX control inside .NET WinForms application - 01-22-2010 , 06:02 AM



Hi, thanks for the reply.

Luckily we have the sources. We have "pinpointed" the problem to the
vsFlexGrid on a user control. If we remove it, the application works.
But ...
If we place the user control *with* the flexgrid directly on our main .NET
screen then the user control *with* the flexgrid works just fine. It's
mind-numbling.
Also, all the COM components work fine (on Windows Vista) when run on a COM
shell. We have replaced the VSFlexGrid (version6) with the latest version
of that commercial control (version 8) and the problem is just the same. To
not exclude any possibility I have sent a mail requesting the PDB files of
these grids (not that I hope they will respond but it doesn't hurt to try).
The only thing that gives us hope right now is that we have so-far been able
to reproduce it pretty consistently on Vista.

"Christian Fröschlin" <froeschlin (AT) mvtec (DOT) com> wrote

Quote:
Willy Van den Driessche wrote:

grid. The grid displays fine and behaves as planned. However, when the
popup menu of the grid is invoked to display a modal (COM) form. Here
however things go wrong.

Do you have access to the source code for the grid and modal form?
If so I'd try to narrow down the problem by removing controls and
code from the form to see if and when the issue goes away.

__________ Informatie van ESET NOD32 Antivirus, versie van database
viruskenmerken 4796 (20100122) __________

Het bericht is gecontroleerd door ESET NOD32 Antivirus.

http://www.eset.com




__________ Informatie van ESET NOD32 Antivirus, versie van database viruskenmerken 4796 (20100122) __________

Het bericht is gecontroleerd door ESET NOD32 Antivirus.

http://www.eset.com

Reply With Quote
  #10  
Old   
Willy Van den Driessche
 
Posts: n/a

Default Solved: System.AccessViolation when opening Modal VB6 Form from Hosted VB6 ActiveX control inside .NET WinForms application - 01-22-2010 , 09:32 AM



My collegue found the solution. We switched from VS2005 to VS2005 some time ago. We still use the framework 2.0 so we thought everythin would be OK. Everything compiled fine and worked fine (on XP where we developed). However, Microsoft silently changed some LINKER.EXE flags to support windows Vista. The defaults where changed.
The short storyis that we need to "post-edit" our executable to explicitly state :

editbin /NXCOMPAT:NO /TSAWARE:NO outexe.exe

This states that our app is not data-execution-prevention aware and does not fully support terminal services. When setting these two flags, everything works again like a charm. Always.
Thanks a bunch Microsoft ! We sought for this bug with 2 persons for 2 full weeks. I can understand that for the large majority of customers this change of default in the linker goes unnoticed and even makes their application "more compliant". But for us it was all but fun.
"Willy Van den Driessche" <alfredothepistolero (AT) hotmail (DOT) com> wrote

Hi,
i have a rather simple question with a large background. We have a huge existing VB6 application consisting of 100+ VB6 com components. We are rewriting this app in .NET. Since there is more than 30 man years in the existing aplication, we are doing this step by step. In the meantime, the old components are hosted in the new .NET Winforms application. They all behave in a similar way : they show a list of items and have a toolbar on top of it. The grid and the toolbar are activeX controls, hosted on the main screen of the .NET application. All components expose a COM class with a common interface. These classes are instantiated by the .NET application and passed to the grid. The grid displays fine and behaves as planned. However, when the popup menu of the grid is invoked to display a modal (COM) form. Here however things go wrong. On Windows XP the application occasionally hangs. On Windows Vista the application crashes 95% of the time with the exception :


---> System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageA(MSG& msg)
at System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.RunDialog(Form form)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog()

I can explain for 3 more pages but that's not the idea. We have tried everything. *any* idea is welcome.




__________ Informatie van ESET NOD32 Antivirus, versie van database viruskenmerken 4794 (20100121) __________

Het bericht is gecontroleerd door ESET NOD32 Antivirus.

http://www.eset.com


__________ Informatie van ESET NOD32 Antivirus, versie van database viruskenmerken 4795 (20100121) __________

Het bericht is gecontroleerd door ESET NOD32 Antivirus.

http://www.eset.com



__________ Informatie van ESET NOD32 Antivirus, versie van database viruskenmerken 4797 (20100122) __________

Het bericht is gecontroleerd door ESET NOD32 Antivirus.

http://www.eset.com

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.