My wpf program worked very well. They moved, to make some changes. Well, I was asked to change some folders in the application. Before I make any changes I ran the application and it is giving me this error:
The type initializer for 'Oracle.DataAccess.Client.OracleConnection' has thrown an exception
The fact occurs in this line:
var diferenca = _listaCommiter().Except(_listaFarm());
This is the complete method code:
private List<string> RetornaDiferenca()
{
List<string> listaDiferenca = new List<string>();
try
{
var diferenca = _listaCommiter().Except(_listaFarm());
foreach (var _diferenca in diferenca)
{
listaDiferenca.Add(_diferenca);
}
diferenca = null;
return listaDiferenca;
}
catch (Exception ex)
{
string r = ex.Message;
return null;
}
}
This is the method _listaFarm()
private List<string> _listaFarm()
{
List<string> lista = new List<string>();
ConexaoBanco cb = new ConexaoBanco();
lista = cb.CriaConexao();
return lista;
}
It's a select on a DB table.
I noticed that in the method where I get the connection, it's giving the problem. Here's the method:
public List<string> CriaConexao()
{
string conexao = ConfigurationManager.ConnectionStrings["FarmExternaConnect"]
.ConnectionString;
List<string> listaArquivoFarmExterna = new List<string>();
OracleConnection conn = new OracleConnection(conexao);
conn.Open();
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandText = "select path, arquivo from gh_arquivos_farm_externa";
cmd.CommandType = CommandType.Text;
try
{
OracleDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
listaArquivoFarmExterna.Add(dr.GetString(0) + dr.GetString(1));
}
return listaArquivoFarmExterna;
}
catch(Exception ex)
{
return null;
}
finally
{
conn.Close();
cmd.Dispose();
}
The error goes along this line:
OracleConnection conn = new OracleConnection(conexao);
This is the inner exception:
The provider is not compatible with the Oracle client version
My connection string:
<add name="FarmExternaConnect" connectionString="Data Source=DESENV; Persist Security Info=True; User ID=Eu; Password=teste"/>
More rows in my app.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework"
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxx"
requirePermission="false"/>
<section name="oracle.manageddataaccess.client"
type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxx"/>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
<appSettings>
<!-- Pastas de Projetos .NET que estão na Farm Externa, separados por vírgula -->
<add key="ProjetosDotNet" value="teste"/>
</appSettings>
<connectionStrings>
<add name="FarmExternaConnect" connectionString="Data Source=DESENV; Persist Security Info=True; User ID=user; Password=teste"/>
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="Oracle.ManagedDataAccess.Client"/>
<add name="ODP.NET, Managed Driver" invariant="Oracle.ManagedDataAccess.Client" description="Oracle Data Provider for .NET, Managed Driver"
type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxx"/>
</DbProviderFactories>
</system.data>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<publisherPolicy apply="no"/>
<assemblyIdentity name="Oracle.ManagedDataAccess" publicKeyToken="xxxxxxxxxxxxxxx" culture="neutral"/>
<bindingRedirect oldVersion="4.121.0.0 - 4.65535.65535.65535" newVersion="4.121.2.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
<oracle.manageddataaccess.client>
<version number="*">
<dataSources>
<dataSource alias="SampleDataSource" descriptor="(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORCL))) "/>
</dataSources>
</version>
</oracle.manageddataaccess.client>
</configuration>