Closed ghost closed 3 years ago
What does manual start mean here?
What does manual start mean here?
just double click ; i release as WinExe
Do you have an appsettings.development.json file in your project? What's in there? That can take priority over appsettings.json when run in VS.
When i run in VS it always works correctly. It break down in release ver when startup with Windows--I mean add it Run in regedit; In project ,i dont have an appsettings.development.json. After release there is one in folder. If i start by meself it works correctly, It can read the appsettings.json. If it start by regedit (Windows) ,program cant read the data in appsettings.json
Do you have an appsettings.development.json file in your project? What's in there? That can take priority over appsettings.json when run in VS.
https://github.com/AldousS22/appsettingsTestDemo/tree/master/appsettingsTestDemo You can have a try .I print the text to event viewer.
Oh, that make sense. ASP.NET relies on the current working directory to find the appsettings.json file. I bet when windows starts the exe it uses a different current directory (maybe c:\windows\system32 like it does for windows services?).
You can log the Environment.CurrentDirectory at startup to confirm this theory. You should also see a log about the Content Root folder. That's where the app looks for the appsettings.json. You can override the location using a command line switch contentroot
.
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/generic-host?view=aspnetcore-3.1#contentroot-1
Oh, that make sense. ASP.NET relies on the current working directory to find the appsettings.json file. I bet when windows starts the exe it uses a different current directory (maybe c:\windows\system32 like it does for windows services?).
You can log the Environment.CurrentDirectory at startup to confirm this theory. You should also see a log about the Content Root folder. That's where the app looks for the appsettings.json. You can override the location using a command line switch
contentroot
. https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/generic-host?view=aspnetcore-3.1#contentroot-1
Thanks. Sry for reply so late. I did it then it works currently. When the program start by regedit, it use the Windows folder not the program folder, so it can find the appsettings. Thanks
Describe the bug
I cant get the appsettings data if I set program startup. Every Time it start, its null. But when i start by myself--after end the thread and manual start the program it works i dont know why. p.s. It also works when i dont set it startup then manual start;
To Reproduce
i dont know how to describe it .
Exceptions (if any)
no exceptions
Further technical details
.net core 3.1 windows 10_2004 OS Name: Windows OS Version: 10.0.19041 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\3.1.403\
Host (useful for support): Version: 3.1.9 Commit: 774fc3d6a9
.NET Core SDKs installed: 3.1.403 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]