Skip to content

BlazorWebView: Use AppContext.BaseDirectory instead of Environment.CurrentDirectory  #21750

Closed

Description

@simonrozsival

This is a follow up to https://github.com/dotnet/maui/pull/21505/files/2d4a1bdabf24a22b8df1e32d4535ebc89f6f7308#r1557824040

In BlazorWebView in WPF and WinForms code, we're using Environment.CurrentDirectory as the app root directory in the case when the location of the entry assembly is not known. This is the case when the app is published as a single file. We should use AppContext.BaseDirectory instead.

Activity

  1. PreciousNyasulu commented on Apr 10, 2024

    @PreciousNyasulu
    Contributor

    Assign it to me

  2. added this to the .NET 9 Planning milestone on Apr 10, 2024
  3. added
    area-blazor
    feature-blazor-sdk
    on Apr 10, 2024
  4. Eilon commented on Apr 16, 2024

    @Eilon
    Contributor

    To repro the original problem:

    1. Build a WinForms or WPF app using BlazorWebView
    2. Publish the app as a single EXE
    3. Run the app from a different folder. That is, say the app is in c:\myapp\cool_app.exe, then in a command prompt navigate to c:\other_folder and run c:\myapp\cool_app.exe

    The original bug was caused by the 'current directory' to be different from where the app is, and due to the app being a single EXE, it couldn't find its own location to locate static assets, so content such as CSS wouldn't load. With the fix in #21797, the app can always locate its files (because the new API works even in single EXE apps), so all the app's content can be found.

  5. added a commit that references this issue on May 6, 2024
  6. locked and limited conversation to collaborators on Jun 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-blazorfeature-blazor-sdkfixed-in-8.0.40fixed-in-9.0.0-preview.5.24307.10

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions