Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writing HTML via BodyWriter is broken when VS.NET "Refresh browser after build" is on. #48897

Closed
1 task done
EamonNerbonne opened this issue Jun 19, 2023 · 3 comments
Closed
1 task done
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions feature-hot-reload This issue is related to the Hot Reload feaature investigate
Milestone

Comments

@EamonNerbonne
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

HTML Responses written via HttpContext.Response.BodyWriter fail (returning empty content) when the asp.net core application is started from VS.NET and the VS.NET option "Projects and Solutions > ASP.NET Core > General > Auto build and refresh" is set to "Refresh browser on build".

This is easily triggered in various configurations, but for example, the following code derived from the ASP.NET core Web API template will trigger it:

using System.Net;
using System.Text;

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.UseHttpsRedirection();

app.MapGet(
    "/html",
    async context => {
        context.Response.StatusCode = (int)HttpStatusCode.OK;
        context.Response.ContentType = "text/html; charset=utf-8";
        new UTF8Encoding(false).GetBytes("Hello, world!", context.Response.BodyWriter);
        //await context.Response.BodyWriter.FlushAsync(); //Required when "Refresh browser after build" is on.
    }
);

app.Run();

Initial analysis shows that something somewhere is trying to inject a script tag referring to aspnetcore-browser-refresh.js. I'm not sure why this results in the response received by the browser being empty.

I tried to find an existing issue for this behavior, and found the following possibly related but non-identical issues:

Expected Behavior

Loading /html of the provided sample in a browser displays a page containing Hello, world!, even when the web server is started directly from VS.NET. Alternatively, if some configuration combination cannot be supported, I'd expect an exception to be thrown and/or a message to be logged somewhere visible.

Steps To Reproduce

using System.Net;
using System.Text;

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.UseHttpsRedirection();

app.MapGet(
    "/html",
    async context => {
        context.Response.StatusCode = (int)HttpStatusCode.OK;
        context.Response.ContentType = "text/html; charset=utf-8";
        new UTF8Encoding(false).GetBytes("Hello, world!", context.Response.BodyWriter);
        //await context.Response.BodyWriter.FlushAsync(); //Required when "Refresh browser after build" is on.
    }
);

app.Run();

Exceptions (if any)

No response

.NET Version

7.0.304

Anything else?

Reproducible with both VS.NET Version 17.7.0 Preview 2.0 and Version 17.6.3

@amcasey amcasey added the feature-hot-reload This issue is related to the Hot Reload feaature label Jun 20, 2023
@tmat tmat assigned tlmii and unassigned tmat Jun 20, 2023
@tmat
Copy link
Member

tmat commented Jun 20, 2023

@tlmii PTAL

@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Aug 25, 2023
@mkArtakMSFT mkArtakMSFT added this to the Backlog milestone Oct 6, 2023
@ghost
Copy link

ghost commented Oct 6, 2023

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@mkArtakMSFT
Copy link
Member

The current script-injection logic is somewhat fragile, and we plan to improve it as part of #45213

@mkArtakMSFT mkArtakMSFT closed this as not planned Won't fix, can't repro, duplicate, stale Dec 1, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Feb 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions feature-hot-reload This issue is related to the Hot Reload feaature investigate
Projects
None yet
Development

No branches or pull requests

5 participants