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

BlazorWebView on Windows Forms locks CSS files while the app is running #7479

Closed
SteveSandersonMS opened this issue May 25, 2022 · 12 comments · Fixed by #9645 or #9787
Closed

BlazorWebView on Windows Forms locks CSS files while the app is running #7479

SteveSandersonMS opened this issue May 25, 2022 · 12 comments · Fixed by #9645 or #9787
Assignees
Labels
area-blazor Blazor Hybrid / Desktop, BlazorWebView blocked Work that is currently blocked external fixed-in-6.0.540 Look for this fix in 6.0.540 SR5! fixed-in-7.0.0-rc.1.6683 platform/windows 🪟 s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working

Comments

@SteveSandersonMS
Copy link
Member

Hot reload for CSS doesn't work for WinForms apps because the files are locked while the app is running, so you can't save changes to them.

Repro

  1. Run a WinForms blazor app
  2. Open wwwroot\css\app.css
  3. Try to save the file. It will prompt to save as since the file is locked.
@SteveSandersonMS SteveSandersonMS added t/bug Something isn't working s/needs-verification Indicates that this issue needs initial verification before further triage will happen area-blazor Blazor Hybrid / Desktop, BlazorWebView labels May 25, 2022
@javiercn
Copy link
Member

@SteveSandersonMS do we know why/how the file is locked?

@SteveSandersonMS SteveSandersonMS added this to the 6.0.3xx-sr1 milestone May 26, 2022
@TanayParikh TanayParikh added s/verified Verified / Reproducible Issue ready for Engineering Triage and removed s/needs-verification Indicates that this issue needs initial verification before further triage will happen labels May 26, 2022
@TanayParikh
Copy link
Contributor

TanayParikh commented May 26, 2022

Confirmed the bug. It's the running winforms app which is holding onto the lock:

image

Filing bug with VS (just need to update to latest first, the above was on 17.2 Preview 6). https://developercommunity.visualstudio.com/t/Resource-Files-Locked-in-Blazor-Hybrid-P/10055002?port=1025&fsid=6e855901-9b89-425f-b0ea-e6774f12f18b&entry=problem

@TanayParikh
Copy link
Contributor

On second thought though, why is the running app using the wwwroot/app.css. Shouldn't it be making a copy in the bin folder? Thoughts @javiercn?

@TanayParikh TanayParikh modified the milestones: 6.0.3xx-sr1, 6.0.3xx-sr2 May 27, 2022
@javiercn
Copy link
Member

Yep, not sure what or why it is being blocked, but during development it must stay in the original wwwroot folder.

@TanayParikh
Copy link
Contributor

TanayParikh commented Jun 7, 2022

I believe this is likely a bug in Visual Studio, specifically related to how it handles file sharing for write (save) operations.

On the Blazor Hybrid WebView end, we request the file from the assembly here:

https://github.com/dotnet/aspnetcore/blob/4aa4ec39894cb9ca4bc5cf50460ded9c46846e23/src/Components/WebView/WebView/src/StaticContentProvider.cs#L75

This in turn goes through the file provider which uses the PhysicalFileInfo to open a read stream to the asset with FileShare.ReadWrite here:

https://github.com/dotnet/runtime/blob/757a1918c7f65183c4e727561dd9962a3afc0566/src/libraries/Microsoft.Extensions.FileProviders.Physical/src/PhysicalFileInfo.cs#L51-L57

So VS shouldn't have any trouble saving the file, unless it's trying to write to the file without FileShare.ReadWrite. If I try to save the file using notepad / notepad++ then I'm able to save it successfully. It is only VS which is having trouble saving the file. This makes me suspect this is a VS file sharing issue during the write/save stage.

Bug has been reported to VS/WinForms team here: https://developercommunity.visualstudio.com/t/Resource-Files-Locked-in-Blazor-Hybrid-P/10055002?viewtype=all / https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1546460

For reference; https://stackoverflow.com/a/3448307

@TanayParikh
Copy link
Contributor

Just an update, closed out the AZDO issue given this is likely not a VS issue, but rather an issue with how the CoreWebView2 handles content streams. MicrosoftEdge/WebView2Feedback#2513

@SteveSandersonMS
Copy link
Member Author

@TanayParikh Does this mean we need to work around it by loading the content into memory and then passing a different stream into WebView2? (Or more efficiently, creating some stream that maps the file data into WebView2 without WebView2 knowing that it comes from a file)

@TanayParikh
Copy link
Contributor

The CoreWebView2 team mentions this issue should be resolved in Edge 104. I'm attempting to validate, and hopefully we're able to close this issue out shortly. 😄

The additional stream specifically for the WebView is definitely an option if the issue isn't resolved in CoreWebView2. I've confirmed it does resolve the issue, ideally however we can avoid it, and the additional associated overhead.

@TanayParikh
Copy link
Contributor

Looks like the CoreWebView2 issue hasn't been resolved unfortunately. They're planning on investigating appropriately.

@TanayParikh
Copy link
Contributor

Just an update on this issue; we've engaged with CoreWebView2, and this does seem to be a bug on their end in which they're not able to close the stream after consumption. Discussing next steps...

@mkArtakMSFT mkArtakMSFT removed this from the 7.0-rc1 milestone Aug 10, 2022
@mkArtakMSFT mkArtakMSFT added this to the .NET 8 Planning milestone Aug 10, 2022
@TanayParikh
Copy link
Contributor

Just an update for those tuning into this issue; continuing to engage with the CoreWebView2 team. They currently have a (internal) PR which attempts to resolve this issue.

@TanayParikh
Copy link
Contributor

This has been confirmed to be resolved via #9645.

Backporting to 6.0: #9787

rmarinho pushed a commit that referenced this issue Aug 31, 2022
…7479

* AutoCloseOnReadCompleteStream

(cherry picked from commit 8dd1316)

* Ensure old response content is closed out for hot reload

(cherry picked from commit ebdfdf4)

* PR Feedback

(cherry picked from commit 122426c)
@ghost ghost locked as resolved and limited conversation to collaborators Sep 29, 2022
@samhouts samhouts added the fixed-in-6.0.540 Look for this fix in 6.0.540 SR5! label Feb 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Blazor Hybrid / Desktop, BlazorWebView blocked Work that is currently blocked external fixed-in-6.0.540 Look for this fix in 6.0.540 SR5! fixed-in-7.0.0-rc.1.6683 platform/windows 🪟 s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
5 participants