We are receiving this error when calling a WCF .net 4.0 service using entity framework.
The 'DbProviderFactories' section can only appear once per config file
It is the first app on the server using EF and other .net 4.0 WCF services are not receiving this error.
Is there any way to correct this error with out editing the machine config file on the server?
The installation for IBM DB2 .NET provider, causes an empty DbProviderFactories, see below. Just delete the second empty entry DbProviderFactories
You have to update Machine.config file located in the below paths.
C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG\Machine.Config
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\Machine.Config
For 64-bit machines, Machine.config will be located in
...\Framework64\...
The block to pay attention to is this:
Maybe you could create web.config entries which override any machine-wide settings you want changed.
Described here:
Override machine.config by web.config
Putting the
<clear />
instruction inside of theDbProviderFactories
tags in the web config to clear out and then override the duplicate entries made in the machine config. Thus doing a hack-work around of the error in the machine.config.As @yonsk already mentioned why this problem occurs (duplicate entry of ), you can create a console application which can fix the machine.config file and then, invoke that console application from your Application's Installer or from your Application whenever you get the Exception. The following code can be used for the console application that will fix the machine.config file.
If you want to call the console application, from your Application, you would need to invoke that as Administrator. So, the following snippet may help to invoke that console application as Administrator (The user will be prompted with a dialog to accept..)