Starting the application with EndPoint Config yields different results

I check for the existence of a file upon application startup; however, the code behaves as if the file is not there.

if (File.Exists("Data/machine.config"))
{
    var doc = new XmlDocument();
    doc.Load("Data/machine.config");
    var machine = doc.SelectSingleNode("/config/SingleAxis | /config/CoreXY | /config/Cartesian");
    if (machine != null)
    {
        builder.Services.AddSingleton<MachineService>();
        builder.Services.AddHostedService(provider => provider.GetRequiredService<MachineService>());

        builder.Services.AddSingleton<AvaloniaUIService>();
        builder.Services.AddHostedService(provider => provider.GetRequiredService<AvaloniaUIService>());
    }
}
else
{
    Debug.WriteLine("No machine.config file found.");
}

Is there some difference between how the debugger runs the code and how the config app runs the code?

“Data/machine.config” is not exist

or you have to do /Data/machine.config, make sure /Data/ folder exist.

Better is “Directory.CurrentDir()/Data/machine.config”

Figured it out. Its just like the problem with finding the wwwroot. You have to set a parameter to store the app root.

var applicationRoot = $"/root/.epdata/{assemblyName}";
var webRoot = $"{applicationRoot}/wwwroot";
Directory.SetCurrentDirectory(applicationRoot);

1 Like