The following forum(s) are migrating to a new home on Microsoft Q&A (Preview): Developing Universal Windows apps!

Ask new questions on Microsoft Q&A (Preview).
Interact with existing posts until December 13, 2019, after which content will be closed to all new and existing posts.

Learn More

 none
[UWP]How to debug WebView.CapturePreviewToStreamAsync() throwing "Catastrophic failure" exception? RRS feed

  • Question

  • I've been using WebView.CapturePreviewToStreamAsync successfully in an UWP app for over a year.  Yesterday I received a crash report where the stack trace contained my method that calls WebView.CapturePreviewToStreamAsync.  So, I fired up VisualStudio and tried to run this code in a debug build.  Sure enough, 9 times out of 10, WebView.CapturePreviewToStreamAsync throws:

     

    - $exception {"Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))"} System.Exception
    - Data {System.Collections.ListDictionaryInternal} System.Collections.IDictionary {System.Collections.ListDictionaryInternal}
    Count 0 int
    IsFixedSize false bool
    IsReadOnly false bool
    IsSynchronized false bool
    + Keys {System.Collections.ListDictionaryInternal.NodeKeyValueCollection} System.Collections.ICollection {System.Collections.ListDictionaryInternal.NodeKeyValueCollection}
    SyncRoot {object} object
    + Values {System.Collections.ListDictionaryInternal.NodeKeyValueCollection} System.Collections.ICollection {System.Collections.ListDictionaryInternal.NodeKeyValueCollection}
    _syncRoot {object} object
    count 0 int
    head null System.Collections.ListDictionaryInternal.DictionaryNode
    version 0 int
    + Results View Expanding the Results View will enumerate the IEnumerable
    HResult -2147418113 int
    HelpLink null string
    IPForWatsonBuckets 0x00007ffc6d88f28f System.UIntPtr
    + InnerException null System.Exception
    IsTransient false bool
    Message "Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))" string
    RemoteStackTrace null string
    Source "System.Private.CoreLib" string
    StackTrace "   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()" string
    + TargetSite {Void Throw()} System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo}
    WatsonBuckets null object
    _HResult -2147418113 int
    _className null string
    - _data {System.Collections.ListDictionaryInternal} System.Collections.IDictionary {System.Collections.ListDictionaryInternal}
    Count 0 int
    IsFixedSize false bool
    IsReadOnly false bool
    IsSynchronized false bool
    + Keys {System.Collections.ListDictionaryInternal.NodeKeyValueCollection} System.Collections.ICollection {System.Collections.ListDictionaryInternal.NodeKeyValueCollection}
    SyncRoot {object} object
    + Values {System.Collections.ListDictionaryInternal.NodeKeyValueCollection} System.Collections.ICollection {System.Collections.ListDictionaryInternal.NodeKeyValueCollection}
    _syncRoot {object} object
    count 0 int
    head null System.Collections.ListDictionaryInternal.DictionaryNode
    version 0 int
    + Results View Expanding the Results View will enumerate the IEnumerable
    _dynamicMethods null object
    _exceptionMethod null System.Reflection.MethodBase
    _helpURL null string
    + _innerException null System.Exception
    _ipForWatsonBuckets 0x00007ffc6d88f28f System.UIntPtr
    _message "Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))" string
    _remoteStackIndex 0 int
    _remoteStackTraceString null string
    _source "System.Private.CoreLib" string
    + _stackTrace {sbyte[48]} object {sbyte[]}
    _stackTraceString null string
    _watsonBuckets null object
    _xcode -532462766 int
    _xptrs 0x0000000000000000 System.IntPtr
    + Static members

    However, my Debug.Writeline output shows that I'm on the main thread and the WebView size is well below the hazardous thresholds:

    Application output:

     webView.Size=[60,607] IsOnMainThread=[True]

    And the stack trace is equally unhelpful:

      

    System.Private.CoreLib.dll!System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() Unknown
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task task) Unknown
    > MyClass.NavigationCompleteB(Windows.UI.Xaml.Controls.WebView webView, Windows.UI.Xaml.Controls.WebViewNavigationCompletedEventArgs args) Line 113 C#

    Here is the method where the exception is triggered:

    private async void NavigationCompleteB(Windows.UI.Xaml.Controls.WebView webView, WebViewNavigationCompletedEventArgs args)

    {

        var ms = new InMemoryRandomAccessStream();
        System.Diagnostics.Debug.WriteLine("webView.Size=[" + webView.Width + "," + webView.Height + "] IsOnMainThread=["+CoreWindow.GetForCurrentThread().Dispatcher.HasThreadAccess+"]");
        await webView.CapturePreviewToStreamAsync(ms);

       // do more stuff here      

    }


    With so little information, how do I debug this?


    Friday, October 11, 2019 1:56 PM

All replies

  • Hi,

    I test your code in my side. But I could not reproduce your issue.

    I'm using the code like this:

                Debug.WriteLine("webView1_NavigationCompleted");
                var ms = new InMemoryRandomAccessStream();
                Debug.WriteLine("webView.Size=[" + webView1.Width + "," + webView1.Height + "] IsOnMainThread=[" + CoreWindow.GetForCurrentThread().Dispatcher.HasThreadAccess + "]");
    
                await webView1.CapturePreviewToStreamAsync(ms);
    
                Debug.WriteLine("test");

    and the output here:

    webView1_NavigationCompleted
    webView.Size=[NaN,NaN] IsOnMainThread=[True]
    test

    So you could see that the function works well in my side and there is no exception about WebView.CapturePreviewToStreamAsync(). I'm running the app which targeting build 1903 on a device with system 1903.

    I need some other information about your issue. What's the target version of your app? What's the version of your device?  Is this error happens to all web links or it just happen to a specific link? Have you test on other devices to see if this issue happens? 

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, October 14, 2019 3:28 AM
    Moderator
  • Roy -

    Thank you for responding.  I finally had some free time to put together a sample project for you.  You can find a GitHub repo for a sample VisualStudio solution that demonstrates this issue:

      github.com/baskren/Forms9Patch/tree/CapturePreviewToStreamAsyncFail

    It is built targeting Windows 10, version 1903 (10.0 build 18362) and I'm testing it on Windows 10 Home, version 10.0.18362.


    Monday, November 4, 2019 7:01 PM
  • FWIW, I tried to add the information from VisualStudio's About screen but this forum will not allow me to post it saying there is an link or image included.
    Monday, November 4, 2019 7:03 PM
  • And yes, I have tried testing of three different Windows 10 devices and all three throw this error.
    Monday, November 4, 2019 7:04 PM
  • Roy -

    I should have mentioned that you want to run the Forms9PatchDemo.Source.UWP project to see the catastrophic failure exception.

    - Ben

    Monday, November 4, 2019 7:53 PM
  • Hi,

    First, I'm sorry to say that I could not run your sample on my side. I checked the code in your sample. I found that you are using this API in HtmlToPngService in the native UWP app. So you are trying to put the UWP app as a dependency of the Xamarin app, right? Since I can't run your demo so I can't debug the app. 

    My suggestion is that create a blank UWP app first, then test the API in the native APP first. If this works correctly, then you could create a new Xamarin app to test. I suspect this is related to Xamarin.

    Anyway, you could also ask about this in the Xamarin's official forum because this issue is more related to Xamarin.

    Best regards,

    Roy


    "Developing Universal Windows apps" forum will be migrating to a new home on Microsoft Q&A (Preview)!
    We invite you to post new questions in the "Developing Universal Windows apps" forum’s new home on Microsoft Q&A (Preview)!
    For more information, please refer to the sticky post.

    Tuesday, November 5, 2019 8:24 AM
    Moderator