WPF Addin -- throws COMException after multiple calls to FrameworkElementAdapters.ViewToContractAdapter(...)

May 13, 2009 at 6:06 PM

Hoping someone can help --

I can consistently recreate the following exception when returning a FrameworkElement from a WPF Addin's GetUI method -- after opening for the eighth time.  It works fine for the first few times it loads, then routinely fails.  I'm using Pipeline builder to create the pipeline -- and the method that fails looks like the following in the contract:

    [AddInContract]

    public interface IAddInContract : IContract

    {

        INativeHandleContract GetUI();

        ....

     } 

 

The UI is a simple WPF UserControl with a button in it.  If I remove the button, I have no issues.  The Exception is thrown at the line:

 

        public virtual System.AddIn.Contract.INativeHandleContract GetUI()

        {

            return System.AddIn.Pipeline.FrameworkElementAdapters.ViewToContractAdapter(_view.GetUI());

        }


Many thanks for any help or thoughts.  Here's the exception;

 

 

Exception from HRESULT: 0x88980406

PresentationCore

 

Server stack trace: 

   at System.Windows.Media.Composition.DUCE.Channel.SyncFlush()

   at System.Windows.Media.MediaContext.CompleteRender()

   at System.Windows.Interop.HwndTarget.OnResize()

   at System.Windows.Interop.HwndTarget.HandleMessage(Int32 msg, IntPtr wparam, IntPtr lparam)

   at System.Windows.Interop.HwndSource.HwndTargetFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)

   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)

   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)

   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)

   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)

   at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)

   at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)

   at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)

   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)

   at MS.Win32.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)

   at MS.Win32.HwndSubclass.DefWndProcWrapper(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)

   at MS.Win32.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)

   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)

   at MS.Win32.UnsafeNativeMethods.SetWindowPos(HandleRef hWnd, HandleRef hWndInsertAfter, Int32 x, Int32 y, Int32 cx, Int32 cy, Int32 flags)

   at System.Windows.Interop.HwndSource.Resize(Size newSize)

   at System.Windows.Interop.HwndSource.OnLayoutUpdated(Object obj, EventArgs args)

   at System.Windows.ContextLayoutManager.fireLayoutUpdateEvent()

   at System.Windows.ContextLayoutManager.UpdateLayout()

   at System.Windows.UIElement.UpdateLayout()

   at System.Windows.Interop.HwndSource.SetLayoutSize()

   at System.Windows.Interop.HwndSource.set_RootVisualInternal(Visual value)

   at System.Windows.Interop.HwndSource.set_RootVisual(Visual value)

   at System.AddIn.Pipeline.FrameworkElementAdapters.ViewToContractAdapter(FrameworkElement root)

   at VCAddinPipeline.AddInSideAdapters.IAddInViewToContractAddInAdapter.GetUI()

   at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)

   at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(RuntimeMethodHandle md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)

   at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)

 

Exception rethrown at [0]: 

   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)

   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)

   at VCAddinPipeline.Contracts.IAddInContract.GetUI()

   at VCAddinPipeline.HostSideAdapters.IAddInContractToViewHostAdapter.GetUI()

   at VCToolkit.VCTookit.OnButtonToolClick(Object sender, RoutedEventArgs e) in c:\dev\dev\src\apps\VCToolkit\VCToolkit\VCTookit.xaml.cs:line 113

2009-05-13 13:59:22,773 VCToolkit.AppMain [1] ERROR - Error on App Startup: System.InvalidOperationException: An unspecified error occurred on the render thread.

   at System.Windows.Media.MediaContext.NotifyPartitionIsZombie(Int32 failureCode)

   at System.Windows.Media.MediaContext.NotifyChannelMessage()

   at System.Windows.Interop.HwndTarget.HandleMessage(Int32 msg, IntPtr wparam, IntPtr lparam)

   at System.Windows.Interop.HwndSource.HwndTargetFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)

   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)

   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)

   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)

   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)

   at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)

   at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)

   at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)

   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)

   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)

   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)

   at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)

   at System.Windows.Threading.Dispatcher.Run()

   at System.Windows.Application.RunDispatcher(Object ignore)

   at System.Windows.Application.RunInternal(Window window)

   at System.Windows.Application.Run(Window window)

   at System.Windows.Application.Run()

   at VCToolkit.App.Main() in c:\dev\dev\src\apps\VCToolkit\VCToolkit\App.cs:line 40