Exception: type initializer for 'system.data.sqlclient.sqlconnection'?

This most likely means that there is an error in your app.config file, e.g. badly formed XML or unexpected elements. The error happens because the static fields inside SqlConnection read from app.config to determine trace detail level as described here: http://msdn.microsoft.com/en-us/library/ms254503.aspx


If you have a project that contains the NuGet packages for both Oracle and SQL Server, this solution might help you fix this error.

Uninstall both of these NuGet packages:

  • Oracle.ManagedDataAccess.Core
  • System.Data.SqlClient

Open your app.config and check if you still have have any dependent assembly entries listed. If you do, delete those entries now. They might look something like this:

<dependentAssembly>
    <assemblyIdentity name="Oracle.ManagedDataAccess" publicKeyToken="89b483f429c47342" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-2.0.19.1" newVersion="2.0.19.1" />
</dependentAssembly>
<dependentAssembly>
    <assemblyIdentity name="System.Data.SqlClient" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.5.0.1" newVersion="4.5.0.1" />
</dependentAssembly>

While still in your app.config file, delete the entire Oracle Managed Data Access section if it exists (This might be the only thing that you need to do to fix this problem, however we performed all of the steps listed in this solution). If you have it, it might look something like this:

<oracle.manageddataaccess.client>
    <version number="*">
      <settings>
          <!-- your TNS_ADMIN value would be located here -->
      </settings>
      <dataSources>
        <dataSource alias="SampleDataSource" descriptor="(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORCL))) " />
      </dataSources>
    </version>
</oracle.manageddataaccess.client>

Open the packages.config file and double check to ensure that the entries for the Oracle and SQL Server packages are not still listed - they should be gone, but it doesn't hurt to be 100% sure.

Save your project, and then re-add the NuGet packages.


Delete app.config and then run the program