looking for appsettings.json
See original GitHub issueWith a recent upgrade (and I can’t tell you whether we are talking Moq. MSTest, .NET Core or Visual Studio)
I am seeing a lot of my tests fail with:
Test method MyTestMethod threw exception:
System.IO.FileNotFoundException: The configuration file 'appsettings.json' was not found and is not optional. The expected physical path was 'D:\....\my project\TestResults\Deploy_MarkHeaton 20230114T084906\Out\appsettings.json'.
Stack Trace:
FileConfigurationProvider.Load(Boolean reload)
ConfigurationRoot.ctor(IList`1 providers)
ConfigurationBuilder.Build()
ActionFilterAttributeTest.ExecuteOnActionExecutingTest(String testName, IHeaderDictionary headerDictionary, IRequestCookieCollection cookieCollection, Type resultType) line 127
BasicAuthenticationAttributeTest.TestBasicAuthenticationAttributeNoUser() line 27
Obviously it is expecting an appsettings.json file in the OUT directory and that is not there. Google suggests issues with active project context with this sort of error.
Any thoughts?
Issue Analytics
- State:
- Created 8 months ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Worker Service looking for appsettings.json in System32 ...
The service is using appsettings.json file for the config information. After installing the service using SC CREATE command, the service was ...
Read more >ASP.NET Core AppSettings.json file
The appsettings.json file is the application configuration file that is used to store configuration settings such as database connection strings, any ...
Read more >ASP.Net Core 2.1 application cannot find appsettings.json ...
json file exists in the published folder. The error message states that is is looking in the C:\WINDOWS\system32\ folder for the appsettings.
Read more >Appsettings.json in .NET: How to read and get a value
The appsettings. json is used in .NET and .NET Core applications to read and get a value from the configuration file using the...
Read more >looking for appsettings.json · Issue #1559 · microsoft/testfx
When I upgrade MSTest.TestAdapter from 2.10.0 to 3.0.2 the tests can no longer find my appSettings.json file. With 2.10.0 the TestContext.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
ok - the issue here is my application, which is a .NET Core website, expects the current directory to be the directory the app is installed into (as do some of the MS libraries I use) and the test framework is setting it to the ‘out’ directory and so all the relative paths break and it also can’t find appsettings.json.
Adding this
keeps it working as I would expect
I just did investigate your reproducer and this is a breaking change behaviour documented (https://github.com/microsoft/testfx/blob/main/docs/Changelog.md#300---2022-12-06), in particular the entry
[breaking change] Unify DeploymentDirectory location across target frameworks https://github.com/microsoft/testfx/pull/1414
. There was a long standing bug where theDeploymentDirectory
was not pointing to the correct directory. But because of the time it took to fix the issue, a lot of people got time to rely on this behaviour.There is nothing better but updating your code that we could recommend.