dotnet / dotnet/dotnet-api-docs
Make Microsoft.Extensions.Configuration.Xml more tolerant against not supported XML features
- Dominant language
- C#
- Stars
- 949
- Forks
- 1.7k
- Avg merge
- 3d 27m
- Merged PRs (30d)
- 49
Description
I ran into a problem with the current implementation of Microsoft.Extensions.Configuration.Xml.
With Visual Studio 2019 16.2.1 I created a new Console App (.NET Framework) application,
added NuGet packages Microsoft.Extensions.Configuration.Xml and NLog.Extensions.Logging,
added code `var configuration = new ConfigurationBuilder().AddXmlFile(Assembly.GetExecutingAssembly().Location + ".config").Build();`
into main function,
started the program and got an exception:
> System.FormatException
> HResult=0x80131537
> Message=XML namespaces are not supported. Line 7, position 22.
> Source=Microsoft.Extensions.Configuration.FileExtensions
> StackTrace:
> at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load(Boolean reload)
> at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load()
> at Microsoft.Extensions.Configuration.ConfigurationRoot..ctor(IList`1 providers)
> at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()
> at ConsoleApp1.Program.Main(String[] args)
I looked into the generated app.config file and found following XML data:
```
```
The reason of FormatException is attribute "xmlns" of element "assemblyBinding".
I wonder, why files with XML namespace declarations are completely rejected.
My expectation would be, that XML features, that are not yet implemented or cannot be implemented due to their nature of not being mappable to key-value-pairs,
are ignored, perhaps writing a warning into log file and all other elements are loaded into memory.
So does it make sense to change the behaviour, instead of throwing an exception ignoring such elements and write a warning into log file?
Contributor guide
Assessment
This issue has not been assessed yet.