none
System.AddIn AddInProcess and WPF

    Question

  • Hi, 
      I figured that I could use the .NET AddIn model to start AddIns in their own process (with FullTrust). However when the AddIn returns an UI, I get the following exception in my code,

    "The calling thread must be STA, because many UI components require this."

    in the constructor for the AddIn


    Here are the relevant parts of the code


    In the addIn Host application

    MyAddin addin = addinToken.Activate<MyAddin>(sharedProcess, AddInSecurityLevel.FullTrust);



    In the addIn

    [System.AddIn.AddIn("TheClock")]

    public class Clock : Myddin

    {

    private ClockControl myUi;

    private UIDataContext myDataContext;

    public Clock()

    {

    myUi = new ClockControl();

    myDataContext = new UIDataContext();

    }



    The question simply is, is it possible to have addIns running in different processes return an UI?

    thanks,
    abi


    Wednesday, June 18, 2008 6:15 PM

Answers

All replies

  • I have all the same problem. abishekk, please if you find any solution, let me know about how you resolved this problem.
    Monday, June 23, 2008 11:56 AM
  • Wang Hua from the WPF team just gives me an example on how to workaround this type of issue:

    http://www.cnblogs.com/Files/sheva/Process.zip

    The key to this technique is to start a STA thread in the addin adaption layer, so that the addin is running in UI STA thread.

    Edit: This type of scenario is not fully tested by WPF team, there is some known issues in this type of case, for instance, keyboard navigation such as tabbing will break.

    Hope this helps


    • Marked as answer by Marco Zhou Wednesday, June 25, 2008 10:57 AM
    • Edited by Marco Zhou Wednesday, June 25, 2008 10:59 AM add stuff
    Wednesday, June 25, 2008 10:57 AM
  • Hey, Marco.
    Thanks to you and Wang for this example solution. It will be awesome if I can apply it to my issue.

    Thanks again,

    Best Regards,
                Alexander

    Wednesday, June 25, 2008 11:34 AM
  • Hey, Marco, It's me again...the code applied to my issue perfectly...
    but there is one question:in the Wang's demo project there are these lines:

    //This special adapter has one  
    //1. Cut off the standard WPF tabbing support to ensure that it doesn't do its work on the wrong thread (by ensuring it doesn't do it at  
    value = new IMyNativeHandle(System.AddIn.Pipeline.FrameworkElementAdapters.ViewToContractAdapter(...)); 

    I don't exactly understand what does it mean "
    Cut off the standard WPF tabbing support to ensure that it doesn't do its work on the wrong thread (by ensuring it doesn't do it at  
    "

    Could you explain it?
    Wednesday, June 25, 2008 4:25 PM
  • I think What Wang actually means here is that the current version of WPF addin framework doesn't support tabbing from UIElements in the Host STA thread to the UIElements in the Addin STA thread, but the default implementation of FrameworkElementAdapters.ViewToContractAdapter() will return an INativeHandleContract implementation which supports tabbing, in order to prevent you from tabbing into wrong thread, Wang intentionally create a custom INativeHandleContract implementation to replace WPF's built-in one. So that tabbing doesn't work at all (since it's not supported in multi-threading scenarios).

    Hope this clears things up a little bit.
    Thursday, June 26, 2008 7:15 AM
  • Thanks, Marco. Now it is totally clear to me what is this code for.

    BR, Alexander 
    Thursday, June 26, 2008 8:49 AM

  • I'm working on a Add-In based solution and I'm using the AddInProcess for isolation.
    However, I  can't find a way on how to use the UnhandledExceptionHandler.
    I would like to log/disable the faulty add-in.

    Wang's code has a comment:

            // catch the addin appdomain exception and shutdown the addin
            //private void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)

    Any ideas, hints how this needs to be implemented?

    thanks,
    raidevnet
    Sunday, July 20, 2008 8:32 AM
  • RaiDevNet, Hi there.

    You can handle ProcessExited event of the addin process, I think, to log/disable the faulty addin.

    Russians never give up!
    Monday, July 28, 2008 8:13 AM
  • Hi

    I am also using the AddInProcess isolation coupled with WPF add-ins. This has brought several issues that lead me to think that WPF add-ins have only been thought to be used with AppDomain isolation, which is just not enough in my case. I cannot allow the host to crash - at all.

    From my understanding the AddInProcess isolation is also an AppDomain isolation. Since my add-ins are also developed in-house, I have been constrained to insert a mechanism where my add-in has to subscribe to its own unhandled exceptions and then report them to the host before it dies! Using this code on the add-in side:

    AppDomain appDomain = Thread.GetDomain();
    appDomain.UnhandledException += (myUnhandledExceptions);



    Why?? can I not access the AppDomain of the add-in in the same way as with only AppDomain isolation:

    AddInController.GetAddInController(myAddIn).AppDomain[.UnhandledException]

    (which I would expect, but AppDomain is null)


    Thanks,

    Sophie

    Thursday, October 16, 2008 1:19 PM
  • Why is it that it seems AddInProcess.ShuttingDown never fires?
    I have an AddInProcess that terminates unexpectedly, but the host doesnt know about it because this event isnt ever fired....

    I want to AVOID putting lifecycle methods in the AddIn contract at all costs...

    Thanks
    Wednesday, October 22, 2008 2:29 AM
  • Hi Sophie.
    AddInProcess isolation uses another process to host an AddIn, so if AddIn is crached down, the AddinProcess.exe also crashes while the main application still lives. You can handle ProcessExited event of addin process to know which addin has just died.
    I'll write some code about this issue for you in few days.

    Russians never give up!
    Wednesday, October 22, 2008 3:55 PM
  • Hi, Nimble. This event is fired only on valid shutting down of addin.

    Russians never give up!
    Wednesday, October 22, 2008 3:56 PM
  • Hi Alexander,
    Well, then I am waiting for your code :)
    I could not find a way to get the information I needed out of the ProcessExited event.

    Your answer does not really answer my question which was:

    If my add-in can access its own AppDomain and play with the UnhandledExceptions, why can't the host reach it too?

    Have a nice evening

    Wednesday, October 29, 2008 3:52 PM
  • Hi Marco, can you explain why this code no longer works under .NET 4.0RC?

    Thanks!
    Saturday, February 27, 2010 8:22 AM
  • Hi,

    I need also help. The Process Sample doesn't work, if I'm using .NET 4.0.

    The follwing exception occurs with .NET 4.0 at this line:

    FrameworkElement

     

     

    element = c.GetUI();

    ((Panel)this.Content).Children.Add(element); // at this line!

    Exception:

    System.Runtime.Serialization.SerializationException wurde nicht behandelt.

      Message=Ungültiger Typcode in Stream "Invalid".

      Source=mscorlib

      StackTrace:

        Server stack trace:

           bei System.Runtime.Serialization.Formatters.Binary.__BinaryWriter.WriteValue(InternalPrimitiveTypeE code, Object value)

           bei System.Runtime.Serialization.Formatters.Binary.IOUtil.WriteWithCode(Type type, Object value, __BinaryWriter sout)

           bei System.Runtime.Serialization.Formatters.Binary.BinaryMethodReturn.Write(__BinaryWriter sout)

           bei System.Runtime.Serialization.Formatters.Binary.__BinaryWriter.WriteMethodReturn()

           bei System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)

           bei System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)

           bei System.Runtime.Remoting.Channels.BinaryServerFormatterSink.SerializeResponse(IServerResponseChannelSinkStack sinkStack, IMessage msg, ITransportHeaders& headers, Stream& stream)

           bei System.Runtime.Remoting.Channels.BinaryServerFormatterSink.ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, IMessage& responseMsg, ITransportHeaders& responseHeaders, Stream& responseStream)

        Exception rethrown at [0]:

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

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

           bei System.AddIn.Contract.INativeHandleContract.GetHandle()

           bei MS.Internal.Controls.AddInHost.BuildWindowCore(HandleRef hwndParent)

           bei System.Windows.Interop.HwndHost.BuildWindow(HandleRef hwndParent)

           bei System.Windows.Interop.HwndHost.BuildOrReparentWindow()

           bei System.Windows.Interop.HwndHost.OnSourceChanged(Object sender, SourceChangedEventArgs e)

           bei System.Windows.SourceChangedEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)

           bei System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)

           bei System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)

           bei System.Windows.RouteItem.InvokeHandler(RoutedEventArgs routedEventArgs)

           bei System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)

           bei System.Windows.EventRoute.InvokeHandlers(Object source, RoutedEventArgs args)

           bei System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)

           bei System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)

           bei System.Windows.PresentationSource.UpdateSourceOfElement(DependencyObject doTarget, DependencyObject doAncestor, DependencyObject doOldParent)

           bei System.Windows.PresentationSource.OnVisualAncestorChanged(DependencyObject uie, AncestorChangedEventArgs e)

           bei System.Windows.UIElement.OnVisualAncestorChanged(Object sender, AncestorChangedEventArgs e)

           bei System.Windows.Media.Visual.ProcessAncestorChangedNotificationRecursive(DependencyObject e, AncestorChangedEventArgs args)

           bei System.Windows.Media.Visual.FireOnVisualParentChanged(DependencyObject oldParent)

           bei System.Windows.Media.Visual.AddVisualChild(Visual child)

           bei System.Windows.Media.Visual.InternalAddVisualChild(Visual child)

           bei System.Windows.Media.VisualCollection.ConnectChild(Int32 index, Visual value)

           bei System.Windows.Media.VisualCollection.Add(Visual visual)

           bei System.Windows.Controls.UIElementCollection.AddInternal(UIElement element)

           bei System.Windows.Controls.UIElementCollection.Add(UIElement element)

           bei WindowsApplication3.Window1.LoadAddIn() in C:\Users\Sascha\Desktop\Process\HostApplication\Window1.xaml.cs:Zeile 71.

           bei WindowsApplication3.Window1.OnClick(Object source, RoutedEventArgs e) in C:\Users\Sascha\Desktop\Process\HostApplication\Window1.xaml.cs:Zeile 34.

           bei System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)

           bei System.Windows.RouteItem.InvokeHandler(RoutedEventArgs routedEventArgs)

           bei System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)

           bei System.Windows.EventRoute.InvokeHandlers(Object source, RoutedEventArgs args)

           bei System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)

           bei System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)

           bei System.Windows.Controls.Primitives.ButtonBase.OnClick()

           bei System.Windows.Controls.Button.OnClick()

           bei System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)

           bei System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)

           bei System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)

           bei System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)

           bei System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)

           bei System.Windows.RouteItem.InvokeHandler(RoutedEventArgs routedEventArgs)

           bei System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)

           bei System.Windows.EventRoute.ReInvokeHandlers(Object source, RoutedEventArgs args)

           bei System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)

           bei System.Windows.UIElement.CrackMouseButtonEventAndReRaiseEvent(DependencyObject sender, MouseButtonEventArgs e)

           bei System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)

           bei System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)

           bei System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)

           bei System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)

           bei System.Windows.RouteItem.InvokeHandler(RoutedEventArgs routedEventArgs)

           bei System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)

           bei System.Windows.EventRoute.InvokeHandlers(Object source, RoutedEventArgs args)

           bei System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)

           bei System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)

           bei System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)

           bei System.Windows.Input.InputManager.ProcessStagingArea()

           bei System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)

           bei System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)

           bei System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)

           bei System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)

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

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

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

           bei System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)

           bei MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)

           bei System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

           bei System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

           bei System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Int32 numArgs)

           bei System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)

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

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

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

           bei System.Windows.Threading.Dispatcher.TranslateAndDispatchMessage(MSG& msg)

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

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

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

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

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

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

           bei System.Windows.Application.Run()

           bei WindowsApplication3.App1.Main() in C:\Users\Sascha\Desktop\Process\HostApplication\App.xaml.cs:Zeile 21.

      InnerException:

     

    Friday, June 11, 2010 12:54 PM
  • Hi,

    I'm currently in the process of making a modular application that loads add-ins in a separate AppDomain. But the separation between Host and AddIn is insufficient, as a crashing AddIn may take down the Host and any other running AddIns. Therefore, I'm currently thinking about creating a separate process for each AddIn like

     

    IAddIn addIn = token[0].Activate<AddIn>(new AddInProcess(), AddInSecurityLevel.FullTrust);
    addIn.Initialize(this); //"this" is the Host
    

     

    But it fails while calling the Initialize method (it is not returning any UI, though I'll be calling another method later to bring a UI to the Host) with this error:

    InvalidOperationException: The calling thread must be STA, because many UI components require this.

    I've stumbled upon this thread: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/3c8592f2-14a6-418b-ab11-6d18096aaa0c

    But the accepted solution seems outdated as I can't make it run under the .NET Framework 4 runtime.

    The auto-generated code for the Host application (App.g.cs) bears the [System.STAThreadAttribute()] attribute.

    I would like, if someone would be kind enough, an explanation of what to look out for in order to enable a full .NET 4 modular application to host .NET 4 addins in separate processes. And possibly an example? That would be very kind, as Google (or any other, for that matter) doesn't seem to have any up-to-date information about this.

    Antoine.

    • Merged by Linda Liu Thursday, June 17, 2010 2:28 AM solved
    Friday, June 11, 2010 3:14 PM
  • Hi,

    I'm also interested in any possible help on this matter. The sample doesn't work for me either in .NET 4.

    Here is the thread I started regarding the same issue: http://social.msdn.microsoft.com/Forums/en-SG/wpf/thread/4b4a8bbf-6797-4450-bda3-b8121754e990

    Is there any way to have a process-isolated AddIn with a UI?

    Tuesday, June 15, 2010 11:45 AM
  • Hi again,

    I've managed to find a workaround for the .NET4 limitation. Currently, Marco's solution crashes when we change the target runtime to .NET4

    I've found that it seems to be related to the IntPtr being unable to be serialized, just like the scenario in this (old, 2007!) thread:

    http://social.msdn.microsoft.com/Forums/en/netfxremoting/thread/27f7d5bd-d464-490c-8388-2312e0aa9911

    Maybe the bug has returned, since the stack dump says that the exception is thrown at

    System.Runtime.Serialization.Formatters.Binary.__BinaryWriter.WriteValue(InternalPrimitiveTypeE code, Object value)

    I've adapted Marco's solution to work around this limitation. Basically, I've had to find a way to make the handle to the Hwnd wrapper cross the process/appdomain boundary from the AddInSideAdapter to the HostSideAdapter.

    When the AddIn returns it's response to the Host, the AddInSideAdapter pulls the INativeHandleContract's handle and puts it into a mock class instance as an Int64. When the HostSideAdapter receives this instance, it instantiates a dummy implementation of the INativeHandleContract and puts the Int64 back into the IntPtr handle (cast needed).

    Only then are we able to call FrameworkElementAdapters.ContractToView(INativeHandleContract) with this dummy instance as the parameter, to obtain the desired FrameworkElement.

    I'm fully aware that this is a workaround, and I welcome any comment regarding this.

    Please find a modified version of Marco's solution here: http://sites.google.com/site/karthwpfstuff/Process.zip

    Wednesday, June 16, 2010 12:43 PM
  • Hi all,

    After working closely with the CLR team at Microsoft, they have completed a hot-fix to correct this issue in .NET 4.

    I have tested and verified the fix.

    You can find the downloads here:

    http://connect.microsoft.com/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=29638

    and the KB issue is here: http://code.msdn.microsoft.com/KB982638

    Along with the originating connect issue here: https://connect.microsoft.com/VisualStudio/feedback/details/467381/wpf-controls-cannot-be-passed-across-process-boundaries

    Thanks again to the team at Microsoft for their effort in correcting this issue.

    Monday, June 21, 2010 10:55 PM
  • Hi all,

    After working closely with the CLR team at Microsoft, they have completed a hot-fix to correct this issue in .NET 4.

    I have tested and verified the fix.

    You can find the downloads here:

    http://connect.microsoft.com/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=29638

    and the KB issue is here: http://code.msdn.microsoft.com/KB982638

    Along with the originating connect issue here: https://connect.microsoft.com/VisualStudio/feedback/details/467381/wpf-controls-cannot-be-passed-across-process-boundaries

    Thanks again to the team at Microsoft for their effort in correcting this issue.


    This worked for me Thanks a ton.
    Tuesday, October 05, 2010 8:31 AM
  • I am able to get my addins ui in Host but certain times i am getting this error "Failed to connect to an IPC Port: The system cannot find the file specified. "

    I am using VS2010 .NET 4.0 AFTER KB982638 FIX INSTALLED

    This is the stack trace

     


    Server stack trace:
       at System.Runtime.Remoting.Channels.Ipc.IpcPort.Connect(String portName, Boolean secure, TokenImpersonationLevel impersonationLevel, Int32 timeout)
       at System.Runtime.Remoting.Channels.Ipc.ConnectionCache.GetConnection(String portName, Boolean secure, TokenImpersonationLevel level, Int32 timeout)
       at System.Runtime.Remoting.Channels.Ipc.IpcClientTransportSink.ProcessMessage(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream, ITransportHeaders& responseHeaders, Stream& responseStream)
       at System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMessage(IMessage msg)

    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 System.AddIn.Contract.INativeHandleContract.GetHandle()
       at MS.Internal.Controls.AddInHost.BuildWindowCore(HandleRef hwndParent)
       at System.Windows.Interop.HwndHost.BuildWindow(HandleRef hwndParent)
       at System.Windows.Interop.HwndHost.BuildOrReparentWindow()
       at System.Windows.Interop.HwndHost.OnSourceChanged(Object sender, SourceChangedEventArgs e)
       at System.Windows.SourceChangedEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
       at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
       at System.Windows.PresentationSource.UpdateSourceOfElement(DependencyObject doTarget, DependencyObject doAncestor, DependencyObject doOldParent)
       at System.Windows.PresentationSource.OnVisualAncestorChanged(DependencyObject uie, AncestorChangedEventArgs e)
       at System.Windows.UIElement.OnVisualAncestorChanged(Object sender, AncestorChangedEventArgs e)
       at System.Windows.Media.Visual.ProcessAncestorChangedNotificationRecursive(DependencyObject e, AncestorChangedEventArgs args)
       at System.Windows.Media.Visual.ProcessAncestorChangedNotificationRecursive(DependencyObject e, AncestorChangedEventArgs args)
       at System.Windows.Media.Visual.ProcessAncestorChangedNotificationRecursive(DependencyObject e, AncestorChangedEventArgs args)
       at System.Windows.Media.Visual.FireOnVisualParentChanged(DependencyObject oldParent)
       at System.Windows.Media.Visual.AddVisualChild(Visual child)
       at System.Windows.FrameworkElement.set_TemplateChild(UIElement value)
       at System.Windows.Controls.ContentPresenter.UseContentTemplate.BuildVisualTree(FrameworkElement container)
       at System.Windows.StyleHelper.ApplyTemplateContent(UncommonField`1 dataField, DependencyObject container, FrameworkElementFactory templateRoot, Int32 lastChildIndex, HybridDictionary childIndexFromChildID, FrameworkTemplate frameworkTemplate)
       at System.Windows.FrameworkTemplate.ApplyTemplateContent(UncommonField`1 templateDataField, FrameworkElement container)
       at System.Windows.FrameworkElement.ApplyTemplate()
       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
       at System.Windows.UIElement.Measure(Size availableSize)
       at System.Windows.ContextLayoutManager.UpdateLayout()
       at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
       at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()
       at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
       at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
       at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.DispatcherOperation.InvokeImpl()
       at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
       at System.Threading.ExecutionContext.runTryCode(Object userData)
       at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Windows.Threading.DispatcherOperation.Invoke()
       at System.Windows.Threading.Dispatcher.ProcessQueue()
       at System.Windows.Threading.Dispatcher.WndProcHook(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, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
       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 Infosys.Buzz.App.Main() in D:\Solutions\Buzz\Source\AddinFramework\Buzz\Infosys.Buzz\obj\x86\Debug\App.g.cs:line 0
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()

    Tuesday, October 05, 2010 12:50 PM
  • "Failed to connect to an IPC port" errors usually mean that the hosting process of your addin is not running at the time your host tries to call a method on said addin.

    Debug your addin to see wether it crashes at any point of its lifetime.

    Thursday, October 07, 2010 9:40 AM
  • Thanks Antonie for the input.yeah my addin got diconnected in between.

    Can i have intercommunications between addins hosted in different processes ?

     

    Monday, October 11, 2010 6:04 AM
  • You can make two addins communicate by the means of an IPC infrastructure, although System.Addin doesn't provide anything for that matter.

    IPC by the means of System.Addin classes is meant to occur between an addin and its Host.

    You will have to code it yourself.

    Monday, October 11, 2010 12:12 PM
  • While activating the addin after installation of patch for .net framework 4.0 for MAF

    HostView.

     

    CustomAddIn c = token.Activate<HostView.CustomAddIn>(ap,AddInSecurityLevel.Host);

    Sometimes i am getting an error ObjectDisposedException is unhandled by the user code . Safe handle has been closed.This issue doesnt repeat in all runs

    Has microsoft has some solution for it ?

    Stack trace is as follows


    Server stack trace:
       at System.Threading.WaitHandle.WaitOneNative(SafeHandle waitableSafeHandle, UInt32 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext)
       at System.Threading.WaitHandle.InternalWaitOne(SafeHandle waitableSafeHandle, Int64 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext)
       at System.Threading.WaitHandle.WaitOne(Int32 millisecondsTimeout, Boolean exitContext)
       at System.Threading.WaitHandle.WaitOne()
       at AddInSideAdapter.AppDispatcher..ctor() in D:\Solutions\Research\VS2010 ADDINS\Process\AddInSideAdapter\AppDispatcher.cs:line 57
       at AddInSideAdapter.AppDispatcher.get_Current() in D:\Solutions\Research\VS2010 ADDINS\Process\AddInSideAdapter\AppDispatcher.cs:line 25
       at AddInSideAdapter.ViewToContractAddInAdapter..ctor(CustomAddIn view) in D:\Solutions\Research\VS2010 ADDINS\Process\AddInSideAdapter\ViewToContractAddInAdapter.cs:line 21
       at ViewToContractAddInAdapter_ConstructorInvoker(Object )
       at System.AddIn.Hosting.ActivationWorker.CreateAddInAdapter(Object addIn, Assembly addinAdapterAssembly)
       at System.AddIn.Hosting.ActivationWorker.Activate()
       at System.AddIn.Hosting.AddInServerWorker.Activate(AddInToken pipeline, ActivationWorker& worker)
       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.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 System.AddIn.Hosting.AddInServerWorker.Activate(AddInToken pipeline, ActivationWorker& worker)
       at System.AddIn.Hosting.AddInActivator.ActivateOutOfProcess[T](AddInToken token, AddInEnvironment environment, Boolean weOwn)
       at System.AddIn.Hosting.AddInActivator.Activate[T](AddInToken token, AddInProcess process, PermissionSet permissionSet)
       at System.AddIn.Hosting.AddInActivator.Activate[T](AddInToken token, AddInProcess process, AddInSecurityLevel level)
       at System.AddIn.Hosting.AddInToken.Activate[T](AddInProcess process, AddInSecurityLevel level)
       at WindowsApplication3.Window1.LoadAddIn() in D:\Solutions\Research\VS2010 ADDINS\Process\HostApplication\Window1.xaml.cs:line 86
       at WindowsApplication3.Window1.OnClick(Object source, RoutedEventArgs e) in D:\Solutions\Research\VS2010 ADDINS\Process\HostApplication\Window1.xaml.cs:line 34
       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
       at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
       at System.Windows.Controls.Primitives.ButtonBase.OnClick()
       at System.Windows.Controls.Button.OnClick()
       at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
       at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)
       at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
       at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
       at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
       at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
       at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
       at System.Windows.Input.InputManager.ProcessStagingArea()
       at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
       at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
       at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
       at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at System.Windows.Interop.HwndSource.InputFilterMessage(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, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)

     

     

    Tuesday, October 12, 2010 10:12 AM
  • Hi,

    When we are loading an addin in a process and if addin is doing some resource intensive work then it hangs or make irresponsive my host process. Why its not behaving in an isolated way ?

    Anuj

    Thursday, October 14, 2010 11:50 AM
  • Hello...does anyone know if there's an official forum for System.Addin?

    The problem i'm interested in is this:

    If you use AppDomain isolation one can load shared libraries(which are not in the same folder as the Addin itself...and ARE NOT registered in the GAC because we just don't want that EVER) you can just get a list of reference assemblies of the addin(load the assembly in i'ts own appdomain ...get referenced assemblies...find them on the disk and then load them using the AppDomain.Load function.Everything works great...wuhu and so on!

    Now...any unhandled crashes in this appdomain will still bring down the application.So one could just use AddinProcess isolation which would fix that problem....BUT...

    There is no mechanism to access the AppDomain inside the process in which the addin is activated.

    Are there any plans to let the developers...access the appdomain inside the process before the addin is activated and load those assemblies...or AT LEAST provide a setting to tell the process where to look for aditional assembly files.

    Did anymore manage to get pass this limitation and if so...how?

    THANK YOU!

     

    Tuesday, November 02, 2010 7:15 PM
  • Hi Looooooka,

    Have you tried something like this? Assuming you already are using System.Addin to activate your addins, you can access a given addin's AppDomain:

    AddInController addInController = AddInController.GetAddInController(myAddin);
    AppDomain domain = addInController.AppDomain;
    

    Reference: http://msdn.microsoft.com/en-us/library/system.addin.hosting.addincontroller.aspx

    Wednesday, November 03, 2010 3:56 PM
  • Hi Looooooka,

    Have you tried something like this? Assuming you already are using System.Addin to activate your addins, you can access a given addin's AppDomain:

     

    AddInController addInController = AddInController.GetAddInController(myAddin);
    
    AppDomain domain = addInController.AppDomain;
    
    

     

    Reference: http://msdn.microsoft.com/en-us/library/system.addin.hosting.addincontroller.aspx

    It's not accessible when you activate an addin using a process
    Thursday, November 04, 2010 12:23 AM
  • Hi Nimble

    I have just loaded the Hot Fix KB982638 and I am still getting the error. Here is my code

          AddInToken sampleModuleAddIn = caclToken[0];
    
          AddInProcess proc = new AddInProcess();
          
          _sampleModule = sampleModuleAddIn.Activate<ISampleModule>(proc, AddInSecurityLevel.Host);
          
          _panel2.Content = _sampleModule.GetAddInUI(); // Error thrown here
    

    I am running on Windows XP sp3 on a 32 bit machine.

    This is the error I am getting

      InnerException: System.InvalidOperationException

           Message=The calling thread must be STA, because many UI components require this.

    This hot fix updated the libraries in the framework folder "C:\WINNT\Microsoft.NET\Framework\v4.0.30319" Is there anything else I need todo for this? In my project I don't reference System.Runtime.Remoting will GAC get automatically updated with this hotfix?

    Thanks

    Victor

     

    • Proposed as answer by Nick Vetter Thursday, February 23, 2012 8:04 AM
    • Unproposed as answer by Nick Vetter Thursday, February 23, 2012 8:05 AM
    Thursday, January 06, 2011 10:53 PM
  • When i am trying to add 3 visual wpf addin in .net 4.0 framework most of the times all 3 dont turned up some times 2 turned up and sometime one but same code in f/w 3.5 sp1 works fine ? In eventvwr i can see the log I can see the message as could not find the remote server . Please help me out from this unusual behaviour of addin .net f/w 4.0.

     

    Regards,

     

    Anuj

    Friday, April 01, 2011 10:18 AM
  • Is there somebody out there who ever fixed this problem:

    The calling thread must be STA, because many UI components require this.

    If so please help me ^^

    thanks

    john


    • Edited by johbic30 Wednesday, April 18, 2012 3:14 PM
    Wednesday, April 18, 2012 2:50 PM
  • I am still getting problem with .NET 4.5. Unable to run WPF addin in seperate process. However it works fine in same process. The calling thread must be STA, because many UI components require this. Can anyone please process answer?

    I followed following article to create AddIn that returns UI but as soon as I try to activate in seperate process. I get same error: The calling thread must be STA, because many UI components require this.

    http://msdn.microsoft.com/en-us/library/bb909849%28v=vs.110%29.aspx



    Thursday, January 23, 2014 4:58 AM