UnauthorizedAccessException when adding WebBrowser to WP7

As part of my project to build a Windows Phone 7 client for www.imaybelate.com, I require a WebBrowser component so that I can process the OpenId login requests that my application supports. After adding the WebBrowser to the XAML, I started getting this exception when I navigated to the page.



Expanding the exception’s details and viewing the stack trace, I immediately spotted that the exception originated in the WebBrowserInterop constructor.

at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
at MS.Internal.XcpImports.CreateObjectByTypeIndex(UInt32 typeIndex, UInt32 managedTypeHandle)
at System.Windows.DependencyObject..ctor(UInt32 nativeTypeIndex, IntPtr constructDO)
at System.Windows.DependencyObject..ctor(UInt32 nativeTypeIndex)
at System.Windows.UIElement..ctor(UInt32 nKnownTypeIndex)
at System.Windows.FrameworkElement..ctor(UInt32 nKnownTypeIndex)
at MS.Internal.TileHost..ctor()
at Microsoft.Phone.Controls.WebBrowserInterop..ctor(Control webBrowser, WebBrowserInteropCallbacks callbacks)
at Microsoft.Phone.Controls.InteropLifetimeMango..ctor(Control webBrowser, WebBrowserInteropCallbacks callbacks)
at Microsoft.Phone.Controls.WebBrowserCompatibility.GetLifetimeManager(Boolean shouldUseQuirkMax7_0, Control webBrowser, WebBrowserInteropCallbacks callbacks, GetCachedWebBrowserPropertiesCallback propertiesCallback)
at Microsoft.Phone.Controls.WebBrowser..ctor()
at System.Reflection.RuntimeConstructorInfo.InternalInvoke(RuntimeConstructorInfo rtci, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)

After some reviewing of the MSDN documentation, I discovered that in order to use the WebBrowser component, you need to request a capability using the WPManifest.xml file. I added the following line to the Capabilities section.


And bingo! My app now runs the WebBrowser.