I've recently encountered the following error on a client machine:
The 'DbProviderFactories' section can only appear once per config file.
It appears that the machine config contains a duplicate DbProviderFactories element.
<system.data>
<DbProviderFactories>
<add name="IBM DB2 for i .NET Provider" invariant="IBM.Data.DB2.iSeries" description=".NET Framework Data Provider for IBM i" type="IBM.Data.DB2.iSeries.iDB2Factory, IBM.Data.DB2.iSeries, Version=12.0.0.0, Culture=neutral, PublicKeyToken=9cdb2ebfb1f93a26" />
</DbProviderFactories>
<DbProviderFactories />
</system.data>
Manually removing this extra element fixes the problem, and our software can run. However, it has been requested that we try and work around this by perhaps ignoring the duplicate entry inside our own app.config. This is because many clients might have the same issue, and we can't modify everyone's config file.
I've tried adding a <clear/>
element inside the system.data section, to hopefully override what's there already in the machine.config. However, this does not work.
For example
<system.data>
<clear />
<DbProviderFactories>
<add name="Microsoft SQL Server Compact Data Provider 4.0"
invariant="System.Data.SqlServerCe.4.0"
description=".NET Framework Data Provider for Microsoft SQL Server Compact"
type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
</DbProviderFactories>
</system.data>
Is there a way to programmatically ignore the duplicate DbProviderFactories element?
Does an API exist to allow you to modify the machine config?
Can anyone help, or recommend a solution?
Kind regards