AccessViolationException with PowerPoint

Add-in Express™ Support Service
That's what is more important than anything else

AccessViolationException with PowerPoint
 
CageMan




Posts: 21
Joined: 2010-11-04
On my clients computer an AccessViolationException occurs every time PowerPoint starts. I have added this code to the PowerPoint AfterPresentationOpen event.


            var presentation = (_Presentation)hostObj;
            var windows = presentation.Windows;
            using (new ComObject(windows))
            {
                   try
                   {                
                    var count = windows.Count;
                    if (count == 0)
                        return;
                   }
                   catch (AccessViolationException)
                   {                
                   }
            }


The exception occurs on the VSTA_Main thread when I call the windows count property. Please find below the stack trace.

Assembly Full Name: AddinExpress.MSO.2005, Version=6.7.3061.2005, Culture=neutral, PublicKeyToken=4416dd98f0861965
Assembly Version: 6.7.3061.2005

Exception Source: Microsoft.Office.Interop.PowerPoint
Exception Type: System.AccessViolationException
Exception Message: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Exception Target Site: get_Count

---- Stack Trace ----
Microsoft.Office.Interop.PowerPoint.DocumentWindows.get_Count()
AddinExpress.MSO.2005.DLL: N 00000 (0x0) JIT
PF.Production.Addin.AddinModule.adxPowerPointEvents_AfterPresentationOpen(sender As Object, hostObj As Object)
AddinExpress.MSO.2005.DLL: N 0022 (0x16) IL
AddinExpress.MSO.ADXPowerPointAppEvents.DoAfterPresentationOpen(presentation As Object)
AddinExpress.MSO.2005.DLL: N 0008 (0x8) IL

(Outer Exception)
Assembly Full Name: AddinExpress.MSO.2005, Version=6.7.3061.2005, Culture=neutral, PublicKeyToken=4416dd98f0861965
Assembly Version: 6.7.3061.2005

Exception Source:
Exception Type: AddinExpress.MSO.ADXExternalException
Exception Message: An error has occurred in the code of the add-in.
Exception Target Site: Object reference not set to an instance of an object.

---- Stack Trace ----

I have found out that another VSTO addin is loading a hidden presentation in the background. However, I could not find a way to handle this error. Do you have any idea how I can catch this error and handle it?

Best,
Thomas
Posted 22 Jun, 2012 04:31:35 Top
Eugene Astafiev


Guest


Hi Thomas,

I have just tested the following code on my machine with Windows 7 SP1 and Office 2010 (both are x64).

private void adxPowerPointEvents_AfterPresentationOpen(object sender, object hostObj)
{
   var presentation = (PowerPoint.Presentation)hostObj;
   var windows = presentation.Windows;
   try
   {
      var count = windows.Count;
      if (count == 0)
          return;
   }
   catch (AccessViolationException ex)
   {
      System.Windows.Forms.MessageBox.Show(ex.Message);
   }
}


The code works like a charm; I didn't notice anything strange on my road.

Where does the ComObject class come from? Do you run another threads in the add-in?
Posted 22 Jun, 2012 07:11:46 Top
CageMan




Posts: 21
Joined: 2010-11-04
Hi Eugene,

I am not using any threads in my addin. I just created a blank solution and I still have this error. If I place a breakpoint in AfterPresentationOpen method the breakpoint is hit on a thread called VSTA_Main. As soon as I disable this third party addin everything works like a charm.
Posted 23 Jun, 2012 00:32:53 Top
Eugene Astafiev


Guest


Hi Thomas,

Could you please send a sample add-in project which can reproduce the issue to the support e-mail address (see the readme.txt file for details)? I will test it on our PCs.

BTW What PowerPoint version do you have installed on the PC?
Posted 23 Jun, 2012 10:55:22 Top
CageMan




Posts: 21
Joined: 2010-11-04
Hi Eugene,

I am using Windows 7 and Office 2010 (both are x64). Unfortunately my clients customer doesn't allow me to provide you a copy of his add-in. I would be able to send you my test project but I guess it will not help at all. The error only occurs in conjunction with this other add-in. Provided that you are agree, another option would be to connect to my computer remotely. Please let me know what do you think about it.

Best,
Thomas
Posted 24 Jun, 2012 06:39:59 Top
Eugene Astafiev


Guest


Hi Thomas,

Well, we can do a remote session tomorrow. But I think it will not help. May I ask you to test a VSTO based add-in project instead in the fields? Does it work?

Anyway, please remember that our office is open from 9:00AM to 5:00PM (GMT) if want to share your PC/customer remotely.
Posted 24 Jun, 2012 14:10:35 Top
CageMan




Posts: 21
Joined: 2010-11-04
Hi Eugene.

I have created a VSTO based addin for Office 2010. I get the exact same error. Please find below the call stack.

Line 1
[Managed to Native Transition]

Line 2 TestAddin1.DLL!TestAddin1.ThisAddIn.Application_AfterPresentationOpen(Microsoft.Office.Interop.PowerPoint.Presentation pres)

Line 3
[Native to Managed Transition]

Line 4
mscorlib.dll!System.Delegate.DynamicInvokeImpl(object[] args) + 0x6f bytes

Line 5
mscorlib.dll!System.Runtime.InteropServices.ComEventsMethod.DelegateWrapper.Invoke(object[] args) + 0xc2 bytes

Line 6
mscorlib.dll!System.Runtime.InteropServices.ComEventsMethod.Invoke(object[] args) + 0x39 bytes

Line 7 mscorlib.dll!System.Runtime.InteropServices.ComEventsSink.System.Runtime.InteropServices.NativeMethods.IDispatch.Invoke(int dispid, ref System.Guid riid, int lcid,

Line 8
System.Runtime.InteropServices.ComTypes.INVOKEKIND wFlags, ref System.Runtime.InteropServices.ComTypes.DISPPARAMS pDispParams, System.IntPtr pvarResult, System.IntPtr pExcepInfo, System.IntPtr puArgErr) + 0x24e bytes

Line 9
[Appdomain Transition]

Line 10
[Native to Managed Transition]

Line 11
[Managed to Native Transition]

Line 12
AW PowerPoint2010.DLL!AW_PowerPoint_2010.rbnAW.AddShapeToGallary(Microsoft.Office.Tools.Ribbon.RibbonGallery galrShapes) + 0xc6a bytes

Line 13
AW PowerPoint 2010.DLL!AW_PowerPoint_2010.rbnAW.rbnAW_Load(object sender, Microsoft.Office.Tools.Ribbon.RibbonUIEventArgs e) + 0xd3 bytes

Line 14
Microsoft.Office.Tools.Common.Implementation.dll!Microsoft.Office.Tools.Ribbon.RibbonManagerImpl.CreateRibbon(string ribbonId, object context) + 0x139 bytes

Line 15
Microsoft.Office.Tools.Common.Implementation.dll!Microsoft.Office.Tools.Ribbon.RibbonManagerImpl.GetRibbon(Microsoft.Office.Core.IRibbonControl control) + 0x104 bytes

Line 16
Microsoft.Office.Tools.Common.Implementation.dll!Microsoft.Office.Tools.Ribbon.RibbonManagerImpl.Invoke(Microsoft.Office.Tools.Ribbon.RibbonComponentCallback callback, object[] args) + 0x80 bytes

Line 17
Microsoft.Office.Tools.Common.Implementation.dll!Microsoft.Office.Tools.Ribbon.RibbonManagerImpl.System.Reflection.IReflect.InvokeMember(string name, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, object target, object[] args, System.Reflection.ParameterModifier[] modifiers, System.Globalization.CultureInfo culture, s tring[] namedParameters) + 0xf2 bytes

Line 18
[Native to Managed Transition]

Line 19
[Appdomain Transition]
Posted 24 Jun, 2012 23:19:01 Top
Eugene Astafiev


Guest


Hi Thomas,

It confirms my assumptions that the cause of the issue doesn't depend on Add-in Express. Instead, I would recommend contacting the problematic add-in developers because you can reproduce the issue even with a regular VSTO based add-in project.
Posted 25 Jun, 2012 03:09:53 Top
CageMan




Posts: 21
Joined: 2010-11-04
Hi Eugene,

I came up with the idea to use ADXAddinModule.SendMessge() whenever the AfterPresentationOpen event occurs on a different thread and then to handle the OnSendMessage event to perform required actions. I thought OnSendMessage will always occur on the main thread but in my case it occurs like any other event on the VSTA_Main thread. Did I misunderstand something or is it possible that the other addin is messing everything up?
Posted 25 Jun, 2012 05:47:36 Top
Eugene Astafiev


Guest


Hi Thomas,

Yes, you are on the right avenue. It looks like the other add-in is the "real" cause of the issue you faced with. Please try to contact the add-in developers instead.
Posted 25 Jun, 2012 06:05:08 Top