I'm noticed the code
`DataTable table = DbProviderFactories.GetFactoryClasses();`
works different in applications targeted as .NET Framework 4.x and .NET Core 2.x. For the former application I receive the providers list with 4 items and for the latter one the list is empty.
I have read about similar issues and figured out the providers list is stored in mashine.config
file (I have console applications, so I haven't web.config
and have only one app.config
file which is almost empty). So I assume my problem is linked with mashine.config
file(s).
I have found 6 mashine.config
files on my desktop.
c:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config c:\Windows\Microsoft.NET\Framework64\v2.0.50727\CONFIG\machine.config c:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config c:\Windows\winsxs\amd64_netfx-machine_config_ocm_b03f5f7f11d50a3a_6.1.7601.17514_none_81fa0191bdd08961\machine.config c:\Windows\winsxs\x86_netfx-machine_config_ocm_b03f5f7f11d50a3a_6.1.7601.17514_none_c9a73868d24cb267\machine.config
Files from folders v2.0.50727 and winsxs have the "full" section
<system.data>
<DbProviderFactories>
<add name="Odbc Data Provider" invariant="System.Data.Odbc" description=".Net Framework Data Provider for Odbc" type="System.Data.Odbc.OdbcFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<add name="OleDb Data Provider" invariant="System.Data.OleDb" description=".Net Framework Data Provider for OleDb" type="System.Data.OleDb.OleDbFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<add name="OracleClient Data Provider" invariant="System.Data.OracleClient" description=".Net Framework Data Provider for Oracle" type="System.Data.OracleClient.OracleClientFactory, System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<add name="SqlClient Data Provider" invariant="System.Data.SqlClient" description=".Net Framework Data Provider for SqlServer" type="System.Data.SqlClient.SqlClientFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</DbProviderFactories>
</system.data>
but files from v4.0.30319 have the empty one:
<system.data>
<DbProviderFactories/>
</system.data>
I can see it on two PCs, so I don't think my Windows or NET installations are corrupted.
So now here are my questions:
- Am I right in .NET Core 2.x application gets
DbProviderFactories
list frommashine.config
file located in v4.0.30319 folder? - Why this list is empty? I mean, what software is responsible for its filling? Do I need to install/add/restore something?
- Is it safe to add providers list in this file manually (just to copy from "full-list" file)?
Thanks.
Microsoft.EntityFrameworkCore
andMicrosoft.EntityFrameworkCore.SqlServer
packages in my .csproj file, but it isn't to be enough... – Miamy