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

Use AppDomain.CurrentDomain.BaseDirectory to get path of appsettings*.json #375

Merged
merged 4 commits into from Dec 7, 2020

Conversation

nr-ahemsath
Copy link
Member

Description

This fixes #116 by using AppDomain.CurrentDomain.BaseDirectory instead of Directory.GetCurrentDirectory() to get the path where an application's appsettings.json file(s) should be.

Testing

Manually tested an ASP.NET Core 2.2 application hosted in a Windows service. Prior to this fix, this app could not read its New Relic application name setting from appsettings.json even though it was there. After the fix, the app is named correctly as expected. I also tested some other cases (.NET 5.0 console application, ASP.NET Core 2.2 and 3.1 apps hosted in IIS in-process) and app naming via appsettings.json worked as expected.

Changelog

Will update changelog once I have a PR # for this PR.

@nr-ahemsath nr-ahemsath added the bug Something isn't working label Dec 5, 2020
{
// Fall back to previous behavior
applicationDirectory = Directory.GetCurrentDirectory();
}
var environment = env.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code org nit: Can we move var env declaration to right before where it is used on line 38?
Similarly, Can we move the block that sets/checks var environment to right before it is used on line 48?

@nr-ahemsath nr-ahemsath merged commit 0ea221f into main Dec 7, 2020
@nr-ahemsath nr-ahemsath deleted the find-appsettings-when-iishosted-inprocess branch December 7, 2020 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

appsettings.json file not found for .NET Core app hosted in Windows Service or InProcess IIS
2 participants