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

Replace Assembly.Location to AppContext.BaseDirectory #1149

Merged
merged 1 commit into from
Jul 24, 2024
Merged

Replace Assembly.Location to AppContext.BaseDirectory #1149

merged 1 commit into from
Jul 24, 2024

Conversation

sappho192
Copy link
Contributor

@sappho192 sappho192 commented Jul 3, 2024

Pull request type

  • Update
  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes

What is the current behavior?

When you Publish the app which is based on one of the templates (Blank/Compact/Fluent), the app will be crashed since Assembly.GetEntryAssembly()!.Location in App.xaml.cs:23 will always return null.

.ConfigureAppConfiguration(c => { c.SetBasePath(Path.GetDirectoryName(Assembly.GetEntryAssembly()!.Location)); })

This doesn't happen if you "build" the app (both Debug or Release), but when you "publish" it.

This issue also can be notified in build message when you publish the app:
IL3000: 'System.Reflection.Assembly.Location' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'.

Issue Number: N/A

What is the new behavior?

  • The app will be properly published and executed

Other information

Actually the demo app Wpf.Ui.Demo.Mvvm already solved this issue like below, so this can be also applied to the template projects.

Path.GetDirectoryName(AppContext.BaseDirectory)

References:

@sappho192 sappho192 requested a review from pomianowski as a code owner July 3, 2024 15:49
@github-actions github-actions bot added PR Pull request dotnet labels Jul 3, 2024
@pomianowski pomianowski merged commit a407870 into lepoco:development Jul 24, 2024
2 checks passed
@sappho192 sappho192 deleted the fix-assembly-location branch July 25, 2024 00:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dotnet PR Pull request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants