MicrosoftEdge / MicrosoftEdge/WebView2Feedback

[Problem/Bug]: ComException for GetContentAsync() in WebResourceResponseReceived for longer POST data

Open
#4,298 2 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
PowerShell
Stars
526
Forks
67
PR merge metrics
No merged PRs in 30d

Description

What happened?

GetContentAsync() of the event WebResourceResponseReceived event throws a ComException, when posting content that exceeds 123290000 bytes (files of about 125 MB size).

This happens for WinForms and WPF apps, and it happens for the latest SDK 1.0.2210.55, but for an older SDK 1.0.1587.40 as well.
I have not tested it with other runtimes than 120.0.2210.121

It is reproducable for me, so that it works every time for a smaller post size, e.g. 123289000 bytes, and it throws the exception every time I post the longer content with at least 123290000 bytes.

since I have a workaround the importance is moderate for me, but for other use cases it could be important / blocking as well.


long length = 123290000;

 CoreWebView2WebResourceRequest webResourceRequest =
        webViewControl.CoreWebView2.Environment.CreateWebResourceRequest(
        TestUrl,
        "POST",
        new MemoryStream(new byte[length]),
        ""
    );

    webViewControl.CoreWebView2.NavigateWithWebResourceRequest(webResourceRequest);

   ...
private async void CoreWebView2_WebResourceResponseReceived(object? sender, CoreWebView2WebResourceResponseReceivedEventArgs e)
{
   // -> exception occurs here
   await e.Response.GetContentAsync();
}
GetContentAsync threw an exception: System.Runtime.InteropServices.COMException (0xFFFF8300): 0xFFFF8300
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
   at Microsoft.Web.WebView2.Core.CoreWebView2WebResourceResponseView.GetContentAsync()
   at WebView2PostTest.WebView.CoreWebView2_WebResourceResponseReceived(Object sender, CoreWebView2WebResourceResponseReceivedEventArgs e)
Importance

Moderate. My app's user experience is affected, but still usable.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

120.0.2210.121

SDK Version

1.0.2210.55

Framework

Winforms

Operating System

Windows 10

OS Version

19045.3803 (22H2)

Repro steps

In a .NET8 Sample application add webview2 winforms control.
Using following code sample, which includes a test server on localhost:8080

(the problem exists for both WinForms and WPF)

using Microsoft.Web.WebView2.Core;
using System.Diagnostics;
using System.Net;
using System.Text;

namespace WebView2PostTest
{
    public partial class WebView : Form
    {
        const string TestUrl = "http://localhost:8080/";
        public WebView()
        {
            InitializeComponent();
            webViewControl.CoreWebView2InitializationCompleted += WebViewControl_CoreWebView2InitializationCompleted;
            InitializeAsync();
        }

        private async void InitializeAsync()
        {
            await webViewControl.EnsureCoreWebView2Async();
        }

        private void WebViewControl_CoreWebView2InitializationCompleted(object? sender, CoreWebView2InitializationCompletedEventArgs e)
        {
            webViewControl.CoreWebView2.WebResourceResponseReceived += CoreWebView2_WebResourceResponseReceived;
            webViewControl.CoreWebView2.NavigationCompleted += CoreWebView2_NavigationCompleted;

            // start the testserver
            Debug.WriteLine($"Start test server on {TestUrl}");
            StartTestServer();

            // works
            //long length = 123289000;

            // does not work
            long length = 123290000;
            
            // System.Runtime.InteropServices.COMException (0xFFFF8300): 0xFFFF8300
            // at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
            // at Microsoft.Web.WebView2.Core.CoreWebView2WebResourceResponseView.GetContentAsync()
            // at WebView2PostTest.WebView.CoreWebView2_WebResourceResponseReceived(Object sender, CoreWebView2WebResourceResponseReceivedEventArgs e)

            CoreWebView2WebResourceRequest webResourceRequest =
                webViewControl.CoreWebView2.Environment.CreateWebResourceRequest(
                TestUrl,
                "POST",
                new MemoryStream(new byte[length]),
                ""
            );

            // post the request
            Debug.WriteLine($"NavigateWithWebResourceRequest: POST content with {length} bytes.");
            webViewControl.CoreWebView2.NavigateWithWebResourceRequest(webResourceRequest);
        }
        private void CoreWebView2_NavigationCompleted(object sender, CoreWebView2NavigationCompletedEventArgs e)
        {
            Debug.WriteLine($"NavigationCompleted: {webViewControl.Source.AbsoluteUri}");
        }

        private async void CoreWebView2_WebResourceResponseReceived(object? sender, CoreWebView2WebResourceResponseReceivedEventArgs e)
        {
            Debug.WriteLine($"WebResourceResponseReceived for {e.Request.Uri}");

            if (e.Request.Uri == TestUrl)
            {
                Debug.WriteLine($"GetContentAsync");
                try
                {
                    Stream content = await e.Response.GetContentAsync();
                    Debug.WriteLine($"GetContentAsync was successful: \"{new StreamReader(content).ReadToEnd()}\"");
                }
                catch (Exception ex)
                {
                    Debug.WriteLine($"GetContentAsync threw an exception: {ex}");
                }
            }
        }

        private void StartTestServer()
        {
            var serverTask = Task.Run(() =>
            {
                HttpListener listener = new HttpListener();
                listener.Prefixes.Add(TestUrl);
                listener.Start();

                while (true)
                {
                    HttpListenerContext context = listener.GetContext();
                    context.Response.StatusCode = (int)HttpStatusCode.OK;

                    MemoryStream memoryStream = new MemoryStream();
                    context.Request.InputStream.CopyTo(memoryStream);
                    context.Response.Headers.Set("Content-Type", "text/plain");

                    StringWriter outputWriter = new StringWriter();
                    outputWriter.Write($"Response for requested URL {context.Request.Url.AbsoluteUri} with status code {context.Response.StatusCode}.");
                    outputWriter.Write($" ({memoryStream.Length} bytes have been received.)");
                    context.Response.OutputStream.Write(Encoding.UTF8.GetBytes(outputWriter.ToString()));
                    context.Response.OutputStream.Close();
                }
            });
        }
    }
}
Repros in Edge Browser

No

Regression

Don't know

Last working version (if regression)

No response

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided .NET 8 WinForms repro and compare GetContentAsync behavior for POST bodies of 123289000 and 123290000 bytes on the stated WebView2 runtime and SDK. Investigate the WebResourceResponseReceived path and the 0xFFFF8300 COMException. Done would be a confirmed fix or a documented limitation for this threshold.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.