Skip to content

Single-file applications get empty application names and collapsed folders (Assembly.Location is empty) #132

Description

@karlspace

Problem

In a single-file application (PublishSingleFile=true), Assembly.Location is an empty string (IL3000). BAUERGROUP.Shared.Core derives application names and folders from it in several places. In a single-file build they all come out empty or collapse into their parent folder.

Observed on 2026-09-15 with bgIndustrialAutomation Client (Shared.Core 3.0.8), published the way its release workflow does it (-r win-x64 --self-contained true -p:PublishSingleFile=true) and then started:

What Expected Actual
Log file C:\ProgramData\<App>\Logging\<App>.log C:\ProgramData\Logging\.log
ApplicationFolders.ExecutionAutomaticApplicationDataFolder C:\ProgramData\<App> C:\ProgramData (the application's settings file lands directly in C:\ProgramData)
BGLoggerConfiguration.ApplicationName <App> empty (start banner prints --- ---)
NLog logger name (BGLogger) <App> empty
Sentry ApplicationName tag / Logger context property <App> empty, so Sentry.NLog drops both

The same build run from dotnet run (not single-file) behaves correctly, so this only shows up on installed stations. Two different single-file applications on one machine also share the same log file and data folder.

Affected code (main, 02325dd)

  • Application/ApplicationFolders.cs:29 ApplicationBinary, :40 ApplicationFileNameWithoutExtension (and everything built on it: ExecutionApplicationDataFolder, ExecutionCommonApplicationDataFolder, ExecutionAutomaticApplicationDataFolder), :84 ApplicationExecuting
  • Application/ApplicationConfigurationStoreBinary.cs:98
  • Logging/BGLogger.cs:41 (logger name)
  • Logging/BGLoggerConfiguration.cs:28 (ApplicationName, which feeds the log file name, the archive name and the Sentry tag)
  • ErrorTracking/BGErrorTracking.cs:100 (default release name), ErrorTracking/BGErrorTrackingConfiguration.cs:18 (ApplicationName)

Suggested fix

  • For names use assembly.GetName().Name, which works in single-file builds.
  • For directories use AppContext.BaseDirectory, and for the executable path Environment.ProcessPath.
  • Enable <EnableSingleFileAnalyzer>true</EnableSingleFileAnalyzer> in the library, so IL3000 flags any new Assembly.Location use at build time.
  • Add a test that runs the name and folder resolution with an empty Location, or a smoke test against a single-file publish.

Impact on applications

Stations that are already installed keep their settings in C:\ProgramData\<App>.Configuration.json and their log in C:\ProgramData\Logging\.log. Once this is fixed, the folders move to the intended location. The release notes should say so, since applications may need to migrate or look in the old location once.

Activity

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

    bugSomething isn't workingreleased

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions