<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Diaries of a Software Plumber</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/changov/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/changov/feed.xml</link>
    <description />
    <lastBuildDate>Wed, 17 Apr 2019 03:39:42 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Hosting WPF UI cross-thread and cross-process</title>
      <link>https://docs.microsoft.com/archive/blogs/changov/hosting-wpf-ui-cross-thread-and-cross-process</link>
      <pubDate>Mon, 26 Oct 2009 02:39:00 GMT</pubDate>
      <dc:creator><![CDATA[Chango V. - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/changov/2009/10/26/hosting-wpf-ui-cross-thread-and-cross-process/</guid>
      <description><![CDATA[AppDomains are the preferred means for isolating related managed components while still having the...]]></description>
      <content:encoded><![CDATA[<P>AppDomains are the preferred means for isolating related managed components while still having the benefit of efficient in-process communication and relative ease of deployment/activation. The <A href="http://blogs.msdn.com/clraddins/archive/2007/08/06/appdomain-isolated-wpf-add-ins-jesse-kaplan.aspx" mce_href="http://blogs.msdn.com/clraddins/archive/2007/08/06/appdomain-isolated-wpf-add-ins-jesse-kaplan.aspx">CLR Add-In framework</A> along with <A href="http://msdn.microsoft.com/en-us/library/system.addin.pipeline.frameworkelementadapters.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.addin.pipeline.frameworkelementadapters.aspx">FrameworkElementAdapters</A> facilitate building UI consisting of pieces running in different AppDomains. Apart from the Add-In model abstractions, the basic interop interface is a native OS (“Win32”) window. While unfortunate for a composited UI framework like WPF, this is necessary because WPF cannot manage an element tree crossing an AppDomain boundary&nbsp;… and all previous UI frameworks for Windows use child windows as the basic building blocks. ;-) One benefit of having add-ins hosted in child windows, though, is that the “host” and “add-in” don’t need to be both built based on WPF. <A href="http://blogs.msdn.com/clraddins/archive/2008/01/03/support-for-windows-forms-in-hosts-and-add-ins.aspx" mce_href="http://blogs.msdn.com/clraddins/archive/2008/01/03/support-for-windows-forms-in-hosts-and-add-ins.aspx">Here’s how</A> WinForms can get involved too.</P>
<P>In some cases, however, AppDomain isolation does not suffice: </P>
<UL>
<LI><STRONG>Reliability</STRONG>: A hang or a crash in a hosted UI component usually affects the host. In the most basic setup, the UI components run on the same thread, which crosses the AppDomain boundary to deliver window messages to the child window. The host is often not in a good position to catch an exception from the add-in or to distinguish it from an exception coming from its own code. That’s because exceptions often occur in the context of UI event handlers, which are ultimately responses to Win32 input messages, which get delivered to the target window by the message pump of the thread. WPF runs a standard Win32 message loop via Dispatcher.Run(). Application code is not directly involved in this loop, and even if it can be, it could not identify the source of an exception that originated many abstraction layers away.</LI></UL>
<BLOCKQUOTE>
<P>With some effort, a child window can be hosted on its own thread. Since each UI thread is supposed to run&nbsp;a message loop, the above problem could be largely avoided. (On top of that, the host would have to guard every direct call into the add-in’s entry points.) However, the hang problem remains. The native window manager automatically merges the input queues and states of threads that have windows in a parent-child relationship. This is generally very beneficial as it facilitates building seamless UI with focus integration and “accelerator” keys just working across the boundary (which requires Alt/Ctrl/etc. key states to be shared), but the message loops get implicitly synchronized: A call to GetMessage() blocks as long as there are messages at the front of the queue destined for the other window. You could opt out of this synchronization by calling AttachThreadInput(NULL), but then a lot of things that you normally take for granted “break”, and dealing with all induced problems quickly becomes overwhelming. There’s a living proof, though, this approach is viable and greatly beneficial (if you can afford the engineering cost ;-) ): <A href="http://blogs.msdn.com/ie/archive/2008/03/11/ie8-and-loosely-coupled-ie-lcie.aspx" mce_href="http://blogs.msdn.com/ie/archive/2008/03/11/ie8-and-loosely-coupled-ie-lcie.aspx">Loosely Coupled IE</A>.</P></BLOCKQUOTE>
<UL>
<LI><STRONG>Unloading</STRONG>: To begin with, AppDomain unloading is not guaranteed to succeed. The reference documentation for <A href="http://msdn.microsoft.com/en-us/library/system.appdomain.unload.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.appdomain.unload.aspx">AppDomain.Unload()</A> has big enough caveats. On top of that, WPF has its fair share of problems with releasing of native resources and breaking object reference loops on unloading, which tend to show up in the context of CLR Add-Ins. Empirically, we know explicitly calling Dispatcher.InvokeShutdown() in an add-in’s AppDomain, on every thread that has had a Dispatcher or WPF object used on it, is often the practical solution. However, this requires cooperation from the add-in and, at least in the case of partial-trust add-ins, loading a host assembly in the add-in’s AppDomain (to be able to call Dispatcher.InvokeShutdown(), which is a privileged operation). If an add-in gets stuck in native code or merely runs a message loop on some thread that gets no user input (presumably different from the host’s UI thread), AppDomain unloading is guaranteed to fail.<BR>
<LI><STRONG>Native code </STRONG>cannot be easily convinced to follow AppDomain state isolation. This is a common integration challenge with legacy components that were not created with use from managed code in mind. Also, the bitness of the native component needs to be matched with that of the host process. This can be a problem because many legacy components are not available in 64-bit form. (Even the Flash and Silverlight ActiveX controls are not (yet).)</LI></UL>
<P><STRONG>Cross-process UI isolation</STRONG> is the strongest, largely because it’s supported at the OS level. In particular, you can always kill a process and rely on complete cleanup. A typical add-in crash will just leave a blank “hole” in the host’s window. (Incidentally, this is what happens in&nbsp;the browser&nbsp;on the rare occasions the XBAP host process, PresentationHost.exe,&nbsp;just crashes.)&nbsp;The host can detect an unexpectedly vanished add-in process (for example, via Process.WaitForExit()) and restart the add-in. Unfortunately, hangs are still a challenge, due to the forced synchronization of UI thread message queues. But there is an effective mitigation for that: The host can have a “watchdog” thread that periodically pings the add-in’s UI thread and, if found unresponsive, offers the user to forcibly recycle the add-in.</P>
<P>Unfortunately, WPF does not directly work with CLR Add-In model’s out-of-process hosting (and provides subpar input &amp; focus integration even in-process when the add-in’s UI runs on its own thread). First basic problem is that the host process does not start in an STA thread. This can be worked around by using an <EM>add-in side adapter</EM>, but that gets awkward. A further problem is with input flow and tabbing across the thread/process boundary. The HwndSource/IKeyboardInputSink integration we have implemented in the FrameworkElementAdapters is designed for single-threaded cases. When a child window is running on its own thread, it doesn’t need to rely on the host for input, although selective delegation of accelerators may be desirable, but it is often expected to “bubble” unhandled input to the host and/or possibly give the host ‘first chance’ to handle select special keys. A future version of the framework may provide better support for cross-thread UI add-ins.</P>
<P>The easiest way to have part of the UI isolated in a separate process is via an <STRONG>XBAP</STRONG>. You can navigate the WebBrowser control directly to the .xbap file. (This can be WPF’s WebBrowser or WinForms’ or, in a native application, directly IE’s ActiveX control.) The XBAP will run in an instance of PresentationHost.exe, and its child window will be attached to the WebBrowser control. There are, however, some downsides to this approach:</P>
<UL>
<LI>The relatively significant runtime cost of ClickOnce deployment. (The first run can be particularly slow.) 
<LI>You cannot control the bitness of PresentationHost. 
<LI>Before .NET v4, there isn’t a convenient way for active two-way communication between the host application and the XBAP. <A href="http://blogs.msdn.com/changov/archive/2009/03/01/scripting-out-of-an-xbap.aspx" mce_href="http://blogs.msdn.com/changov/archive/2009/03/01/scripting-out-of-an-xbap.aspx">This post</A> presents one somewhat involved but effective technique. 
<UL>
<LI>In v4 we finally provide neat ‘script interop’ with the help of the Dynamic Language Runtime and the language-level support for it. The XBAP’s host application can expose its API through WebBrowser.ObjectForScripting, and the XBAP can access this object&nbsp;via <A href="http://msdn.microsoft.com/en-us/library/system.windows.interop.browserinterophelper.hostscript(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.windows.interop.browserinterophelper.hostscript(VS.100).aspx">BrowserInteropHelper.HostScript</A>. </LI></UL></LI></UL>
<P>Finally, the attached solution illustrates doing cross-process UI hosting directly, using just HwndSource &amp; HwndHost out of the box, running the two message loops, and routing input appropriately through the IKeyboardInputSink implementations of HwndHost and HwndSource. This example solves most of the above problems with in-process/cross-AppDomain hosting and provides good flexibility and performance. Much of the code is actually dedicated to somewhat extrinsic, “implementation-level” problems, but that’s how it typically is with solving real problems… ;-) The highlights:</P>
<UL>
<LI>Asynchronous loading of the add-in for better startup time and to avoid UI thread blocking 
<LI>Use of .NET Remoting based on named pipes for two-way cross-process communication 
<LI>Remotable object lifetime management. Graceful &amp; fallback shutdown of the add-in process 
<LI>Input &amp; focus integration: tabbing in &amp; out; “bubbling” unhandled keys from the add-in to the host 
<LI>Solving threading issues.&nbsp; </LI></UL>
<H5>Input</H5>
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/changov/WindowsLiveWriter/HostingWPFUIcrossprocess_1095F/image_6.png" original-url="http://blogs.msdn.com/blogfiles/changov/WindowsLiveWriter/HostingWPFUIcrossprocess_1095F/image_6.png" mce_href="http://blogs.msdn.com/blogfiles/changov/WindowsLiveWriter/HostingWPFUIcrossprocess_1095F/image_6.png"><IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=image border=0 alt=image src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/changov/WindowsLiveWriter/HostingWPFUIcrossprocess_1095F/image_thumb_2.png" original-url="http://blogs.msdn.com/blogfiles/changov/WindowsLiveWriter/HostingWPFUIcrossprocess_1095F/image_thumb_2.png" width=501 height=505 mce_src="http://blogs.msdn.com/blogfiles/changov/WindowsLiveWriter/HostingWPFUIcrossprocess_1095F/image_thumb_2.png"></A>&nbsp;</P>
<P>The main thread of the “add-in” process runs a Win32-style message loop via Dispatcher.Run(). This would mostly suffice for the child-window HwndSource to get its input, but keyboard input handling generally works better if MSGs straight off the message loop are “preprocessed", before passing them to DispatchMessage()&nbsp;and&nbsp;DefWinowProc(). This helps with correct handling of accelerators, in particular with some ActiveX controls (like the one WebBrowser wraps), and avoids occasional IME translation mishaps. WPF’s Dispatcher provides a direct hook into its message loop via the ComponentDispatcher.ThreadPreprocessMessage event. When HwndSource owns a top-level window, it subscribes itself to ThreadPreprocessMessage and does all the needed preprocessing and routing internally (largely by delegating to its IKeyboardInputSink implementation). But we need a child window for the add-in. The trick I’ve used is to first initialize the HwndSource as a top-level window, while keeping the window invisible, and then immediately convert it to a child one. Fortunately, the native window manager supports this well, and WPF obliviously takes it well too.</P>
<P>To be able to <STRONG>“bubble” unhandled keys</STRONG> to the host, the add-in subscribes a handler of its own to ComponentDispatcher.ThreadPreprocessMessage, counting on it to be called after HwndSource’s. The MSGs are relayed to the host via a custom remotable interface. Then the host obtains the main window’s IKeyboardInputSink implementation and calls TranslateAccelerator() and OnMnemonic(). Where do the messages go further? This arrangement invokes a special input event routing mode of HwndSource: It will see that a child window ("sink") has focus and will create an event route using the wrapper element (the HwndHost here) for the child window as the “forced” target. Thus, any element up to the root visual has a chance to see and handle the events, which is much in keeping with how most WPF routed events work. (The sample application shows a couple of interesting cases of key input delegation.)</P>
<P>For <STRONG>tabbing out</STRONG>, the KeyboardNavigation machinery gives us a special cue by calling IKeyboardInputSite.OnNoMoreTabStops(). The add-in provides a simple implementation of this interface and relays the call to the host, which merely calls MoveFocus() on the HwndHost. For <STRONG>tabbing into</STRONG> the add-in, the host implements IKeyboardInputSink.TabInto() on the HwndHost, which is appropriately called by the internal keyboard navigation code.</P>
<P>The host could selectively give the add-in opportunity to handle keyboard input. Doing so, however, is not analogous to how the add-in bubbles unhandled key input. The main difference is that there is no defined target element within the add-in’s UI, because focus is somewhere within the host’s window. (That’s why the host’s thread is getting the input messages.) Thus, calling IKeyboardInputSink.TranslateAccelerator() on the child-window HwndSource will not route input across that element tree. However, the InputManager will raise its global (per-thread, really) events: PreProcessInput, PostNotifyInput, etc. The add-in could handle these events and filter for specific keys it’s interested it. Or a custom interface could be defined across which to pass “managed” KeyDown events. There is one type of key input that still makes sense to be delegated to the child IKIS: <STRONG>mnemonics</STRONG> (these are Alt+something key combinations). HwndSource’s built-in implementation of IKIS.OnMnemonic() does most of its work independently from focus: It tries to activate AccessKeys within its element tree and then “broadcasts” the input event to any child sinks of its own (say, a WebBrowser control).</P>
<H5>Threading</H5>
<P>The two message loops appear to operate independently, and they are certainly unaware of each other per se. But the OS does the input queue &amp; input state merging I mentioned earlier. Each input MSG is destined to a specific window, but the two message loops are essentially forced to serialize access to their respective messages. This creates implicit synchronization between the two threads (specifically around their message-pumping activity). One unfortunate practical implication is that the add-in can hang the host. A good strategy to mitigate this risk is to avoid doing any non-trivial input processing on the UI thread. While this is healthy practice in general, it’s not a guarantee, it's difficult to be so disciplined,&nbsp;and an external add-in may not cooperate. The “watchdog” feature I described earlier can be implemented if the host needs a stronger reliability guarantee.</P>
<P>Regardless of the specific IPC method chosen, for the two threads to be able to talk to each other, the receiving one has to be awaiting a Win32 message, that is, waiting in a call to the native GetMessage() or similar function or blocked in a message-alertable state supported by MsgWaitForMultipleObjects(). This is the general convention in Windows user-mode programming: A thread can be “hijacked” to respond to an external event (relatively) safely only around message pumping or when explicitly blocked in the special <A href="http://msdn.microsoft.com/en-us/library/ms681951(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms681951(VS.85).aspx"><EM>alertable state</EM></A>. Thus, for a UI thread to be responsive to external “calls”, it’d better be doing what UI threads are supposed to do most of the time: message pumping. </P>
<P>When making a simple, “one shot” call, the calling thread might just block until the call is processed and returned. But if the called thread decides to call back before returning, we have a problem: a <STRONG>deadlock</STRONG>. This kind of <STRONG>“reentrant” calls</STRONG> tend to occur naturally between related UI components, and even handling of basic window state changes such as resizing and focus move require making synchronous handling of window messages sent from one thread to another. Consequently, the calling thread should prepare itself to handle incoming messages <EM>while</EM> waiting for the call it has just made to complete. The most common traditional solution for this problem in Windows has been provided by COM. Being a means for cross-thread and cross-process communication and being used in UI scenarios, it had to. That’s one of the essential features of <EM>Single Threaded Apartments</EM>: Outgoing calls run an efficient local message loop waiting for the call to return and simultaneously dispatching all <A href="http://msdn.microsoft.com/en-us/library/ms644950(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms644950(VS.85).aspx"><EM>sent</EM></A><EM>&nbsp;</EM>window messages and COM runtime’s internal window messages used to marshal STA calls from RPC thread-pool threads to the right thread. The CLR has had to accommodate message-based reentrancy as well, and as a pretty tough compromise at that: “Managed” blocking, such as via WaitHandle.WaitOne(), is window message permeable on an STA thread. While helping with interop scenarios and crucially preventing deadlocks, this tends to bite unexpectedly due to the unintuitive reentrancy allowed by an explicit “blocking” operation and the potentially asynchronous/random nature of such reentrant calls. I should not digress too much, because Chris Brumme has written the <A href="http://blogs.msdn.com/cbrumme/archive/2004/02/02/66219.aspx" mce_href="http://blogs.msdn.com/cbrumme/archive/2004/02/02/66219.aspx">definitive treatise</A> on this subject.</P>
<P>Because I’ve used .NET Remoting, and not COM, for the cross-process communication in the example implementation, I had the somewhat unexpected occasion to experience and ponder the above reentrancy vs. deadlocking issue. It turns out that the particular chosen IPC transport—named pipes (which is the most efficient available out of the box) does pretty hard blocking when sending “messages” and awaiting a response: At the bottom of the abstraction stack, a call to the ReadFile() native function is made to read the response message&nbsp;stream, and this function blocks unconditionally. So, for example, if the add-in tried to bubble some unhandled key to the host and the host decided to talk to the add-in while handling the given key or performed some window operation that affects the add-in’s window too, we’d get a deadlock because the add-in’s main (UI) thread is hard-blocked. To avoid this, all deadlock-prone calls across the boundary (in either direction) are made not from the UI thread but from a worker thread. WPF’s Dispatcher is run on this worker thread to be able to conveniently marshal calls to it. And there is a crucial side effect of calling Dispatcher.Invoke() cross-thread: The calling thread gets blocked in the message-permeable way described above, thus permitting reentrant calls via window messages. How would such a call actually be delivered? Via the Dispatcher again, but that of the pseudo-blocked UI thread. A Remoting call is normally received first on some random thread-pool thread. (That’s just how Remoting works. MarshalByRefObjects are treated as <EM>agile</EM>—not bound to any particular thread; thus, the runtime can deliver an incoming call on any thread.) For calls where some trivial processing is done not involving UI objects, no thread switching is needed. But WPF is pretty unforgiving if any UI object is accessed from a foreign thread. For such cases, that object’s Dispatcher is used to do a callback.</P>
<H5>General Notes</H5>
<UL>
<LI>Most of the example solution and the foregoing discussion are valid for any cross-thread child window hosting, including in-process. In spite of the implicitly UI thread synchronization, overall responsiveness may be better than with single-threaded UI because there is opportunity for true concurrent processing. While you would not get the stronger reliability guarantees afforded by having a separate host process for the child window, performance will be noticeably better, especially if the application-level APIs are chatty. Also, .NET Remoting has special, optimized cross-AppDomain in-process marshaling mode. </LI>
<LI>Also of practical interest is hosting WPF content in non-WPF applications. Since the essential integration interface between the “host” and the “add-in” in the above solution are a native window handle (HWND) and the fairly abstract IKeyboardInputSink, it is conceivable the host side could be implemented without WPF. For a purely native host application, however, .NET Remoting would have to be replaced with another IPC method, the most obvious and versatile choice being COM (and with it the deadlock/reentrancy issue is solved for free :-) ).</LI></UL>
<P>[Update, 4/29/10] Windows hosted by HwndHost tend to flicker heavily on resizing. This really shows with the WebBrowser control in my sample project, perhaps exacerbated by the cross-process window messaging. The solution is shown in this KB article: <A href="http://support.microsoft.com/kb/969728">http://support.microsoft.com/kb/969728</A>. (WFH derives from HwndHost, but the problem really is in HwndHost.) I updated the attached project.</P>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/09/91/28/60/X-Proc%20WPF%20Hosting.zip" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-09-91-28-60/X_2D00_Proc-WPF-Hosting.zip">X-Proc WPF Hosting.zip</a></p>]]></content:encoded>
    </item>
    <item>
      <title>"Scripting out" of an XBAP</title>
      <link>https://docs.microsoft.com/archive/blogs/changov/scripting-out-of-an-xbap</link>
      <pubDate>Sun, 01 Mar 2009 23:57:00 GMT</pubDate>
      <dc:creator><![CDATA[Chango V. - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/changov/2009/03/01/scripting-out-of-an-xbap/</guid>
      <description><![CDATA[[Update: .NET v4 solves this problem in an elegant way by leveraging the Dynamic Language Runtime....]]></description>
      <content:encoded><![CDATA[<p><span style="background-color: #ffffff; color: #008000;">[Update: .NET v4</span> <span style="color: #008000;">solves this problem in an elegant way by leveraging the Dynamic Language Runtime. See </span><span style="color: #008000;"><a href="http://msdn.microsoft.com/en-us/library/system.windows.interop.browserinterophelper.hostscript.aspx">BrowserInteropHelper.HostScript</a>.</span><span style="color: #008000;"> The browser script integration works in Firefox too.]</span></p>
<p>When an XBAP is hosted in an HTML [i]frame, it has limited means to communicate with script in the host page. These are: passing parameters to the startup URL (which can be read from Application.StartupUri or BrowserInteropHelper.Source); exchanging HTTP cookies (Application.Get/SetCookie()); and, as a last resort, use a web service at the site of origin as an intermediary. The biggest obvious limitation of these methods is that they are passive: you don't have the equivalent of a method call. Thus, a commonly requested feature by XBAP developers is the ability to directly communicate with HTML script in the page hosting the XBAP. Until such feature is provided, there is a somewhat unobvious way to do this, but only from a <span style="text-decoration: underline;">full-trust XBAP</span> and only in Internet Explorer. </p>
<p>The basic idea is this: Crawl the browser hosting container hierarchy starting from <a href="http://msdn.microsoft.com/en-us/library/system.windows.interop.browserinterophelper.clientsite.aspx">BrowserInteropHelper.ClientSite</a>; get to the <a href="http://msdn.microsoft.com/en-us/library/aa752127.aspx">IWebBrowser2</a> of the frame hosting the XBAP; then get to the HTML DOM window object, and finally get its <a href="http://msdn.microsoft.com/en-us/library/aa752642(VS.85).aspx">Script</a> object, which represents the scripting environment of the HTML page. Having that object, "the magic" of COM Interop makes script function calls and parameter passing possible. On the managed side, you just do Reflection (late-bound) calls. Unfortunately, this is pretty ugly in C#, but with some helper methods it can be covered up. Since VB.NET has built-in support for late-bound method calls ("scripting"), the calling syntax can be fairly clean.</p>
<p>For HTML script to "call into" the XBAP can be arranged a little indirectly: The XBAP passes a 'scriptable object' to its host page, and then the late-bound calls from script are translated to managed method calls by COM Interop again, just in the opposite direction (via CCWs). The scriptable object needs to be marked with[ComVisible(true)] and expose some public API.</p>
<p>The attached project is a rudimentary demonstration of this technique. Incidentally, it also has an example of other interesting things you can do once you have IE's main interfaces: closing the tab/window in which the XBAP is loaded. (This is something for which there is no managed API. The XBAP can be running top-level in the browser, not in a frame.) </p>
<p>A note on the <b>debugging setup</b>: In Project Properties, the debugging option needs to be set to Start Browser with URL, pointing to HTMLPage1.htm in the bin\Debug output folder. (This setting is per user, so it's not saved in the attached project.) The page hosts the XBAP in an iframe. This is enough for Visual Studio 2008 to be able to start debugging the XBAP, even though it's launched indirectly. (The VS project system has some intrinsic knowledge of XBAPs and coordinates the launch with PresentationHost.exe, the XBAP host process, via the <a href="http://msdn.microsoft.com/en-us/library/aa970051.aspx">-debug and -event parameters</a>.)</p>
<blockquote>
<p>[Update, 10/14/09] On initial loading of the HTML page in IE, script execution will likely be blocked, with an explanatory message in the information bar (aka &lsquo;goldbar&rsquo;). You can click on the prompt and let IE enable running script, but this will start another instance of the XBAP. You could <i>attach </i>to it then with the VS debugger (attach to the running PresentationHost.exe). This gets tedious after a while. Just for debugging, you could let script run automatically by selecting the option to &lsquo;Allow active content to run in files on my computer&rsquo; in Internet Options &gt; Advanced tab &gt; Security section. It is risky to leave the browser running with this setting, so remember to reset it. The script blocking won&rsquo;t happen if you open the host HTMP page from a UNC path or HTTP URL, but unfortunately F5 debugging of the XBAP becomes impractical then.</p>
<p>Another issue you might run into is that the host HTML page will load without the XBAP in it. There may be different reasons for such mishap, but a likely one with the sample is that your anti-virus program sneakily opens the .zip file and puts the <a href="http://www.hanselman.com/blog/RemovingSecurityFromDownloadedPowerShellScriptsWithAlternativeDataStreams.aspx">Zone.Identifier alternate data stream</a> on the files in the archive. Use of Scott&rsquo;s methods to remove the stream.</p>
</blockquote>
<p>Finally, to run an XBAP with full trust, the easiest way is to just run it from the local file system, which is the case of debugging in Visual Studio. If you want to run it non-locally, you have to use the <a href="http://msdn.microsoft.com/en-us/library/01daf08f.aspx">ClickOnce Trusted Application Deployment model</a>, which entails installation of the application's signing certificate on the client computers. (This has been discussed broadly on the web.)</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/09/45/38/20/ScriptInteropDemo.zip" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-09-45-38-20/ScriptInteropDemo.zip">ScriptInteropDemo.zip</a></p>]]></content:encoded>
    </item>
    <item>
      <title>WebBrowser control on transparent WPF window</title>
      <link>https://docs.microsoft.com/archive/blogs/changov/webbrowser-control-on-transparent-wpf-window</link>
      <pubDate>Mon, 19 Jan 2009 15:55:00 GMT</pubDate>
      <dc:creator><![CDATA[Chango V. - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/changov/2009/01/19/webbrowser-control-on-transparent-wpf-window/</guid>
      <description><![CDATA[Many customers are surprised and disappointed to discover that a WebBrowser control (or any native...]]></description>
      <content:encoded><![CDATA[<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Times New Roman','serif'; COLOR: #0f243e; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-themecolor: text2; mso-themeshade: 128"><FONT size=3>Many customers are surprised and disappointed to discover that a WebBrowser control (or any native window, really) hosted in a WPF window with AllowsTransparency=True does not work—problems ranging from broken repainting to the child window/control not appearing at all. This is due to the fundamental “</FONT><A href="http://msdn.microsoft.com/en-us/library/aa970688.aspx"><FONT color=#800080 size=3>airspace” issue</FONT></A><FONT size=3>. In particular, composition involving different rendering technologies supports transparency only with entire top-level windows, not child windows.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Times New Roman','serif'; COLOR: #0f243e; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-themecolor: text2; mso-themeshade: 128"><o:p><FONT size=3>&nbsp;</FONT></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Times New Roman','serif'; COLOR: #0f243e; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-themecolor: text2; mso-themeshade: 128"><FONT size=3>If you must show a WebBrowser control or host any child window (HWND) “in” a WPF window with transparency, here is one workaround technique. The idea is to wrap the native window in a top-level non-WPF one and “float” that window over the area of the main WPF window where the control is supposed to appear, responding to layout and window resizing changes. With appropriate window “styling” and event handling, this can create a pretty good illusion of an actual hosted child window. Of course, you can expect some integration roughness with such a hacky technique, but it may work well enough for you.<o:p></o:p></FONT></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Times New Roman','serif'; COLOR: #0f243e; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-themecolor: text2; mso-themeshade: 128"><o:p><FONT size=3>&nbsp;</FONT></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Times New Roman','serif'; COLOR: #0f243e; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-themecolor: text2; mso-themeshade: 128"><o:p><FONT size=3><IMG style="WIDTH: 680px; HEIGHT: 619px" title="Transparent web browser control screenshot" alt="Transparent web browser control screenshot" src="http://blogs.msdn.com/changov/attachment/9341075.ashx" width=678 height=606 mce_src="http://blogs.msdn.com/changov/attachment/9341075.ashx">&nbsp;</FONT></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Times New Roman','serif'; COLOR: #0f243e; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-themecolor: text2; mso-themeshade: 128"><o:p><FONT size=3>&nbsp;</FONT></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Times New Roman','serif'; COLOR: #0f243e; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-themecolor: text2; mso-themeshade: 128"><FONT size=3>So, how is this trick even possible, if child window composition does not work with transparency? (The hosted control/native window is still a child window.) Well, it does work when the “system-managed” transparency mode is used and all windows in the hierarchy use GDI for drawing. Dwayne has a great </FONT><A href="http://blogs.msdn.com/dwayneneed/archive/2008/09/08/transparent-windows-in-wpf.aspx"><FONT color=#800080 size=3>overview of the two transparency modes</FONT></A><FONT size=3> supported by Windows and how WPF relates to them. We cannot use a WPF window to host the native control, or we are back to the original problem. The easiest way to create a GDI window with the system-managed transparency/composition is via WinForms. This is what the attached prototype project does. To make that “overlay” window (wrapped by a System.Windows.Forms.Form object) appear as much as possible as a child window of the main WPF window, it has ShowInTaskbar=False and FormBorderStyle=FormBorderStyle.None. Additionally, it has the main window set as its </FONT><A href="http://msdn.microsoft.com/en-us/library/ms632599(VS.85).aspx#owned_windows"><FONT size=3>owner</FONT></A><FONT size=3>. This takes care of minimize+restore behavior and automatically destroys the owned window with the main one.<o:p></o:p></FONT></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Times New Roman','serif'; COLOR: #0f243e; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-themecolor: text2; mso-themeshade: 128"><o:p><FONT size=3>&nbsp;</FONT></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Times New Roman','serif'; COLOR: #0f243e; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-themecolor: text2; mso-themeshade: 128"><FONT size=3>To define where in the main window the hosted control should appear, we designate a “placement target” element, which could be a border, panel, or some other FrameworkElement. The “overlay” window has to be moved and/or resized in response to the owner window moving or the placement target element moving in layout or getting resized. Since in typical situations the location of the placement target will remain fixed relative to the window borders, responding only to its SizeChanged event is a good optimization. There is no LocationChanged event, and I don’t know if there is any more efficient way to get a notification like this than to handle every LayoutUpdated event (which looks like a per-instance event, but it’s really per layout pass, which can affect many elements across the tree).<o:p></o:p></FONT></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Times New Roman','serif'; COLOR: #0f243e; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-themecolor: text2; mso-themeshade: 128"><o:p><FONT size=3>&nbsp;</FONT></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Times New Roman','serif'; COLOR: #0f243e; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-themecolor: text2; mso-themeshade: 128"><FONT size=3>If you need the WebBrowser control in particular and you want to avoid the dependence on WinForms, you could use a WPF window as the “overlay” one and WPF’s System.Windows.Controls.WebBrowser, but you have to give up on the browser control being transparent. The attached prototype project illustrates this alternative. (The button at the top of the initial window opens the WPF-based version.)<o:p></o:p></FONT></SPAN></P>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/09/34/10/92/WebBrowserOnTransparentWindow.zip" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-09-34-10-92/WebBrowserOnTransparentWindow.zip">WebBrowserOnTransparentWindow.zip</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Introduction</title>
      <link>https://docs.microsoft.com/archive/blogs/changov/introduction</link>
      <pubDate>Thu, 30 Aug 2007 16:35:00 GMT</pubDate>
      <dc:creator><![CDATA[Chango V. - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/changov/2007/08/30/introduction/</guid>
      <description><![CDATA[A somewhat awkward but necessary first step... 
I am a Software Development Engineer on the WPF...]]></description>
      <content:encoded><![CDATA[<P>A somewhat awkward but necessary first step... </P>
<P>I am a Software Development Engineer on the WPF Application Model team. This is the team that brings you the goods of windows, the <A class="" href="http://msdn2.microsoft.com/en-us/library/ms750478.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms750478.aspx">navigation framework</A>, browser-hosted applications (XBAPs), resource loading, <A class="" href="http://blogs.msdn.com/clraddins/archive/2007/08/06/appdomain-isolated-wpf-add-ins-jesse-kaplan.aspx" mce_href="http://blogs.msdn.com/clraddins/archive/2007/08/06/appdomain-isolated-wpf-add-ins-jesse-kaplan.aspx">visual add-ins</A>,&nbsp;and a bunch of miscellaneous, mostly infrastructure type of&nbsp;services.&nbsp;Oh, and of course the <A class="" href="http://msdn2.microsoft.com/en-us/library/ms743714.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms743714.aspx">Application class</A> ;-). </P>
<P>My personal areas are browser hosting/integration, Win32 Interop, and navigation/journaling, so my posts will likely be around these topics. After months of&nbsp;semi-regular participation on the <A class="" href="http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=119&amp;SiteID=1" mce_href="http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=119&amp;SiteID=1">WPF MSDN Forum</A>, I realize I need a more coherent and more easily discoverable repository for various pieces of useful product information and FAQs. And maybe I will throw in an occasional tidbit or good lesson learned from my day to day experience as a developer.</P>
<P>I drew significant inspiration from reading blogs.msdn.com to join Microsoft (which happened a little over two years ago). Now I feel it's an honor to be able to start my own. I'm just not sure how well I'll manage to keep it up. But "nothing ventured, nothing gained", they say. ;-)</P>]]></content:encoded>
    </item>
    <item>
      <title>XBAP deployment failures and collecting diagnostic information</title>
      <link>https://docs.microsoft.com/archive/blogs/changov/xbap-deployment-failures-and-collecting-diagnostic-information</link>
      <pubDate>Thu, 30 Aug 2007 14:33:00 GMT</pubDate>
      <dc:creator><![CDATA[Chango V. - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/changov/2007/08/30/xbap-deployment-failures-and-collecting-diagnostic-information/</guid>
      <description><![CDATA[[Update 6/12/08] A tool that repairs the most commonly occurring permission problems failing XBAP...]]></description>
      <content:encoded><![CDATA[<p><span style="font-family: 'Arial','sans-serif'; color: #00682f; font-size: 10pt">[Update 6/12/08] A tool that repairs the most commonly occurring permission problems failing XBAP deployment has been released: </span><span style="font-family: 'Calibri','sans-serif'; color: #1f497d; font-size: 11pt"><a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=adb47247-4e27-4490-a153-39d8334172d9">http://www.microsoft.com/downloads/details.aspx?FamilyID=adb47247-4e27-4490-a153-39d8334172d9</a></span><span style="font-family: 'Calibri','sans-serif'; color: #231165; font-size: 11pt">. </span><span style="font-family: 'Calibri','sans-serif'; color: #00682f; font-size: 11pt">Shortly, the Watson service will start offering it to users of affected computers.</span><span style="font-family: 'Calibri','sans-serif'; color: #1f497d; font-size: 11pt"> </span><span style="font-family: 'Arial','sans-serif'; color: #00682f; font-size: 10pt"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></span></p> <p>We occasionally hear from users (mostly developers) about XBAPs unexplainably failing to start on particular computers. This is troubling news when everything is installed correctly on the system and the XBAP itself is known to be good. There are many pieces involved in XBAP deployment &amp; activation, some of them external to WPF, and only one has to be slightly out of whack in order for the whole process to fail. Unfortunately, there isn't just one known cause, and the failure symptoms are often such that figuring out what exactly is broken is not easy, or just impossible for end users. As a core infrastructure feature, XBAP deployment should be highly reliable. That's why we are trying to identify the top common causes and then implement solutions in the next version/service pack of the framework. To this end, we need feedback from "the real world", where computer configurations vary greatly and OS and software installations are anything but fresh and done in a particular order.</p> <p>First, whenever you get a Dr.Watson dialog saying the "Windows Presentation Foundation Host has encountered a problem and needs to close", <em>please</em> send the report. (PresentationHost.exe is the process that hosts an XBAP. Even though the application visually runs within the browser's window, it's loaded in a separate process for better isolation and reliability.) This is the best way for us to learn about deployment failures in the field, measure frequency of occurrence, and possibly request additional system information to be automatically sent with subsequent reports of a particular failure. If the hosted application (the XBAP) crashes, the managed exception should be caught and shown formatted in an HTML page, in place of the application's content. The Watson dialog almost always suggests the crash is due to a platform bug or to a critical system configuration problem.</p> <p>Because currently all managed exceptions are caught and shown in the XBAP error page, we are preventing Watson from reporting failures due to bugs in the managed part of the framework. We'll likely add a mechanism in a future release to enable sending a report of any managed exception. This will help both us and XBAP vendors to improve reliability. Also, in SP1 (and .NET v3.5), a number of possible deployment error conditions and the majority of previously silent failures will trigger a Watson report.</p> <p>For now, you can just look at the exception call stack shown in the error page and try keyword search using symbols from the top few frames. Solutions for some common causes can thus easily be found. </p> <p>In particular, errors from ClickOnce are frequently occurring. You can recognize them by the assembly name and namespace - System.Deployment. Here's a sample: </p> <p><img title="Sample XBAP deployment error from ClickOnce" alt="Sample XBAP deployment error from ClickOnce" src="http://farm2.static.flickr.com/1301/1280435060_6c2cad060e.jpg" mce_src="http://farm2.static.flickr.com/1301/1280435060_6c2cad060e.jpg"></p> <p>There are certain ClickOnce errors that tend to occur mostly or only on developers' computers, when multiple builds of an application are deployed and in particular when doing so from different locations (URLs) and without incrementing the version number. Then you may have a corrupt ClickOnce application store (cache). To clear it, run this command from an SDK command window: <em>mage -cc</em> and/or directly delete the store folder:</p> <ul> <li><span style="font-family: 'Calibri','sans-serif'; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa">x:\Documents and Settings\username\Local Settings\Apps - on Windows XP</span>  <li><span style="font-family: 'Calibri','sans-serif'; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa">x:\Users\username\AppData\Local\Apps - on Windows Vista.</span></li></ul> <p>If this doesn't help, you may have a case of a bad framework installation or bad system configuration... </p> <p>A group of known issues is with NT permissions on certain system objects. The most frequently occurring case seems to be with the HKCU\Software\Classes registry key. The problem, an experimental workaround, and a manual fix are discussed <a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=395439&amp;SiteID=1&amp;PageID=1" mce_href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=395439&amp;SiteID=1&amp;PageID=1">in this Forum post</a>. The gist is that the individual user's account has to be explicitly given Full Control permission. Getting this permission via membership in the Administrators group is not sufficient, because PresentationHost runs with a restricted process token. Similar, mostly isolated, problems have been observed with these objects as well:</p> <ul> <li>"x:\Documents and Settings\username\Local Settings\Application Data" folder and/or Deployment subfolder  <li><span style="font-family: 'Calibri','sans-serif'; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa">"x:\Documents and Settings\username\Local Settings\Apps" folder. This is the main storage for the ClickOnce application cache and mage -cc clears it, but it may&nbsp; not be able to resolve NT permission problems.</span>  <li><span style="font-family: 'Calibri','sans-serif'; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa">HKCR\Interface\{79EAC9C9-BAF9-11CE-8C82-00AA004BA90B} key</span></li></ul> <p><span style="font-family: 'Calibri','sans-serif'; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa">PresentationHost.exe released with .NET 3 SP1 and .NET v3.5 will detect these specific configuration problems, trigger Dr. Watson, and if the user chooses to send a report, we'll present a response page that leads to some patch utility. Unfortunately, for a number of reasons it is not possible to automatically resolve each of these possible permission problems at the time the framework is installed, so we have to rely on this indirect method.</span></p> <p><span style="font-family: 'Calibri','sans-serif'; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa"><strong>Collecting diagnostic information</strong>&nbsp;</span></p> <p><span style="font-family: 'Calibri','sans-serif'; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa">If you have a case of XBAP deployment failure and the XBAP itself is known to be good (runs on another computer, other than the one on which it was built), and you are not seeing the ACL/permission anomaly involving any of the above file/registry objects, then it may be due to a yet-unknown cause, and providing us with specific diagnostic information can help us figure out the cause and possibly address it in a future release. Besides the Windows, .NET framework and browser version information, two types of logs are usually sufficient.</span></p> <p><span style="font-family: 'Calibri','sans-serif'; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa"><strong>I. From </strong><a href="http://www.microsoft.com/technet/sysinternals/ProcessesAndThreads/processmonitor.mspx" mce_href="http://www.microsoft.com/technet/sysinternals/ProcessesAndThreads/processmonitor.mspx"><strong>Process Monitor</strong></a>. Set up two filters: 'Process name is PresentationHost.exe'&nbsp; and 'Process name is iexplore.exe'. (Keep the default filters. They eliminate a lot of noise.) For Firefox, the process name is Firefox.exe. (Note that only v3.5+ will support XBAPs in Firefox.)</span></p> <p><span style="font-family: 'Calibri','sans-serif'; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa"><span style="font-family: 'Calibri','sans-serif'; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa">[Update, 10/10] It really helps if Process Monitor captures stack traces for logged events. To enable this, ProcMon needs dbghelp.dll v6 or newer. The file path is given to it in the Configure Symbols dialog, from the Options menu. You can get the right dbghelp.dll in at least two ways:</span></span></p> <ul> <li><span style="font-family: 'Calibri','sans-serif'; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa"><span style="font-family: 'Calibri','sans-serif'; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa">It's part of Visual Studio: "c:\Program Files\Microsoft Visual Studio 8\Common7\IDE\dbghelp.dll" </span></span>  <li><span style="font-family: 'Calibri','sans-serif'; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa"><span style="font-family: 'Calibri','sans-serif'; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa">You can download <a href="http://www.microsoft.com/whdc/devtools/debugging/default.mspx" mce_href="http://www.microsoft.com/whdc/devtools/debugging/default.mspx">Debugging Tools for Windows</a>.</span></span></li></ul> <p><span style="font-family: 'Calibri','sans-serif'; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa"><strong>II. </strong><a href="http://msdn2.microsoft.com/en-us/library/aa363787.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/aa363787.aspx"><strong>ETW</strong></a><strong> traces</strong>. Both IExplore (v7) and PresentationHost are instrumented to trace significant events (when tracing is enabled). Unfortunately, the Windows SDK tools for trace collection and manipulation are not very user friendly. Just for collection, the WPFPerf tool shipped with the .NET Framework SDK suffices.</span></p><span style="font-family: 'Calibri','sans-serif'; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa"> <p style="text-indent: -0.25in; margin: 0in 0in 0pt 0.5in" class="MsoListParagraph">1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; From an SDK command window, start wpfperf.exe. (The tool is documented here: <a href="http://msdn2.microsoft.com/en-us/library/aa969767.aspx">http://msdn2.microsoft.com/en-us/library/aa969767.aspx</a>) On Windows Vista, the tool has to be run elevated.</p> <p style="text-indent: -0.25in; margin: 0in 0in 0pt 0.5in" class="MsoListParagraph">2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If that’s the first time you are starting it, the Add Tool dialog will pop up. (If not, get it from the File menu.) Select the Event Trace tool. (This is a consumer/logger for ETW events. WpfPerf combines a bunch of different tools in one shell.)</p> <p style="text-indent: -0.25in; margin: 0in 0in 0pt 0.5in" class="MsoListParagraph">3.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; In the middle-right part of the Event Trace window, click Add.</p> <blockquote> <p style="text-indent: -0.25in; margin: 0in 0in 0pt 0.5in" class="MsoListParagraph">a.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; In Add New Logger, enter: Logger name = PH [just a name], GUID = “WPF – All” [from the drop-down list], some file path with .etl extension. Click Add.</p> <p style="text-indent: -0.25in; margin: 0in 0in 0pt 0.5in" class="MsoListParagraph">b.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; While still in Add New Logger, change GUID to “NT Kernel Logger”. Enter a different filename (.etl). Click Add.</p> <p style="text-indent: -0.25in; margin: 0in 0in 0pt 0.5in" class="MsoListParagraph">c.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If you are using IE 7, also add a logger for it with these parameters: <font size="2">Logger name: IE7<br></font><font size="2">GUID: 797FABAC-7B58-4796-B924-D51178A59CE4<br></font><font size="2">Log file: c:\temp\IE.etl<br></font><font size="2">Level: 5<br></font><font size="2">Flags: 4294967295</font></p></blockquote> <blockquote> <p style="text-indent: -0.25in; margin: 0in 0in 0pt 0.5in" class="MsoListParagraph">d.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Click Done.</p></blockquote> <p style="text-indent: -0.25in; margin: 0in 0in 0pt 0.5in" class="MsoListParagraph">4.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Select each logger in the list box and click Start.</p> <p style="text-indent: -0.25in; margin: 0in 0in 0pt 0.5in" class="MsoListParagraph">5.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; In Internet Explorer, enter the URL of an XBAP in the address line. Wait until the error occurs or the browser just goes idle without any response. (The navigation globe/wheel may keep spinning on error, though. This happens when the navigation sequence was aborted abnormally in the middle.)</p> <p style="text-indent: -0.25in; margin: 0in 0in 0pt 0.5in" class="MsoListParagraph">6.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Go back to WPFPerf and stop the loggers.</p> <p style="text-indent: -0.25in; margin: 0in 0in 0pt 0.5in" class="MsoListParagraph">(Since you should be doing the Process Monitor capturing in parallel, stop/pause it at this time as well.)</p> <p style="text-indent: -0.25in; margin: 0in 0in 0pt 0.5in" class="MsoListParagraph">7.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; To make sure events were captured, look at the .etl file sizes. They should be several hundred KB each. The IE one may be smaller.</p> <p style="text-indent: -0.25in; margin: 0in 0in 0pt 0.5in" class="MsoListParagraph">8.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Compress the resulting .etl files, and put the archive on some web server where we can copy it from. </p> <p style="text-indent: -0.25in; margin: 0in 0in 0pt 0.5in" class="MsoListParagraph" mce_keep="true">&nbsp;</p> <p style="text-indent: -0.25in; margin: 0in 0in 0pt 0.5in" class="MsoListParagraph">Notes:</p> <p style="text-indent: -0.25in; margin: 0in 0in 0pt 0.5in" class="MsoListParagraph">·&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; It’s best to act quickly during logging so that we don’t accumulate too many kernel events. Start logging just when you are ready to navigate to the XBAP in the browser.</p> <p style="text-indent: -0.25in; margin: 0in 0in 0pt 0.5in" class="MsoListParagraph">·&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The Open Logs button in the tool probably won’t show you anything from the WPF trace file. There is a bug in the first release that prevents the events generated by the hosting code (PresentationHost) from being shown. But they are in the .etl file. And you should be able to display the kernel events, although not in a very digestible form.</p> <p style="text-indent: -0.25in; margin: 0in 0in 0pt 0.5in" class="MsoListParagraph">&nbsp;</span><span style="font-family: 'Calibri','sans-serif'; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa"><span style="font-family: 'Calibri','sans-serif'; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa">&nbsp;</span></span></p> <p><span style="font-family: 'Calibri','sans-serif'; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa"><span style="font-family: 'Calibri','sans-serif'; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa">When done with the log collection, please send a description of your problem, symptoms and system information along with the logs link to xbap-sos at micrsoft . com [Microsoft intentionally misspelled here]. A team member will try to help. Please understand that we cannot guarantee responses for each case. For general help with XBAPs, please post to the <a href="http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=119&amp;SiteID=1" mce_href="http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=119&amp;SiteID=1">WPF Forum</a>.</span></span></p> <p><span style="font-family: 'Calibri','sans-serif'; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa"></span></p>]]></content:encoded>
    </item>
  </channel>
</rss>