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
API proposal: Add AppContext.ApplicationConfig #29271
Comments
If we are doing this just for compatibility with .NET Framework, we should just add the exact API that exists for this in .NET Framework and nothing more: https://docs.microsoft.com/en-us/dotnet/api/system.appdomainsetup.configurationfile?view=netframework-4.7.2
|
I do not think that this makes sense to propagate this legacy stuff into the host. The host is complicated enough as is. |
We already have the ability to pass in arbitrary key/value pairs through the host into I can live with not adding another property on |
The AppDomainSetup.ConfigurationFile property is a full path. The arbitrary key/value pairs do not work well for full paths - they get invalidated when the app moves. Which part of the system would compute the full path for
I do not understand the problem with getting in front of the static constructor for ConfigurationManager. This constructor will run only once something uses the ConfigurationManager. If the app wants to configure the path to the configuration file, it can do it in the Main method before using the configuration manager. It is similar how one configures other global defaults, e.g. My suggestion would be to introduce a new |
You're responsible for giving a full path if you use this method. Much as you would be if you were passing this in on desktop or setting the property directly before spinning up a new appdomain.
It isn't always possible due to external dependencies, etc. In addition, test harnesses can't make a universal fix without this. They need to point to the "normal" app.config before user code runs.
I've considered that but I don't want to do it for a couple of reasons.
|
So how does test harnesses make a universal fix with the API proposed at the top, without rearchitecting to allow setting this? |
They push the config file path through when the host is launched, or possibly hook into the new pre-main extensibility. https://github.com/dotnet/corefx/issues/32095#issuecomment-483425717 Passing the value through to the CLR host seems like the most dependable way and that would be what I would recommend when possible. I'm particularly skittish about this as I hit a similar problem with PowerShell not setting the long path flags until after they started the host and started running code. They just programmatically set the flag, despite my objections. Something else got in front and floored a bunch of internal tools recently. It took coming to me for them to figure out what was happening and what they could do to mitigate the problem. Given that any of the options here are often insanely difficult for people to diagnose when they go wrong I'd much rather go with the hardest to accidentally break option. :) |
Ok, we do not really need any new API to make this work. All that needs to happen for this is that System.Configuration calls AppContext.GetData to read what was set in the config file. |
For the pass in key-value pair, sure. You can't programmatically set via the host startup hook this way however. I've split out the "bring back" and "new, but not strictly needed" APIs above. |
You can: |
We don't currently expose it: https://github.com/dotnet/corefx/blob/master/src/System.Runtime/ref/System.Runtime.cs#L102 |
Hmmm, I have not realized that this one of those APIs that are public in CoreLib, but not exposed in refs.
|
Missed that myself. :) I'll implement based on that to start/unblock, but I'd still like to see it come from the property. |
It is fine to have API for configuration values like these, but the APIs should live together with the component that they are configuring. It does not make sense to have a configuration for every component out there in CoreLib. The random grab-bag of things on AppDomainSetup in desktop was not a good design. |
Is there any progress on this? For us, such a feature would be really really useful. our use case is: we have netcoreapp host application which tries to load as plugins different modules. Every of such modules has its own config file - assembly_name.dll.config. |
Conclusion
|
@maryamariyan Fyi, this is |
I do not think it makes sense to add this API to support legacy configuration system since we have lived for multiple releases without it now. |
While
app.config
isn't the way we configure Core, plenty of ported libraries still useSystem.Configuration
. We don't exposeConfigurationFile
onAppDomainSetup
any more and we hack it's path directly inSystem.Configuration
.A common pattern, particularly for testing frameworks, is to fire up a new
AppDomain
with a custom config file. As we only have a singleAppDomain
on Core this isn't possible and is creating some serious pain in porting larger more complicated projects. We can provide the customization at the hosting level by exposing a property likeAPP_CONTEXT_CONFIGURATION_FILE
much like we doAPP_CONTEXT_BASE_DIRECTORY
.See #931 and linked issues for more.
We could also add another field to
AppContext
to see what this setting is, but it isn't strictly necessary. ForAPP_CONTEXT_BASE_DIRECTORY
we expose it fromAppContext.BaseDirectory
. To follow suit we would add (and populate the default forAppDomainSetup
above from this):The text was updated successfully, but these errors were encountered: