8
votes

I am trying to connect to oracle database from .net core 3.1 using ado.net here's my code

private OracleConnection GetOracleConnection()
{
            string conString = "Data Source=Q550.adr.XXXX.com;Persist Security,Info=True;User ID=XXXX;Password=CCC39";
            OracleConnection con = new OracleConnection(conString);
            return con;
}

but when this function executes following exception occured at line number 2

System.TypeInitializationException: 'The type initializer for 'OracleInternal.Common.ProviderConfig' threw an exception

FileNotFoundException: Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified. **

Can anyone tell me what's happening ??

1
Try this : Go to project properties and uncheck prefer 32 bit. - Clint
By any chance, do you refer the ConfigurationManager.ConnectionStrings or added ConfigurationManager in your namespace? In .net core, you need to include the System.Configuration as a package to use the ConfigurationManager object to access the AppSettings and ConnectionStrings. - Ak777
alternatively , you can Install-Package System.Configuration.ConfigurationManager from nuget - Clint
"prefer 32 bit" is unchecked (by default when creating the project) and doesn't solve the problem. Installing System.Configuration.ConfigurationManager as you suggest does it. - Sebastian Palma
exactly same problem here when trying to connect to MySQL - Leo Muller

1 Answers

13
votes

You can Install System.Configuration.ConfigurationManager from Nuget

Install-Package System.Configuration.ConfigurationManager

This problem is a known issue as you can see here and the recommended solution is nuget package

https://github.com/pusher/pusher-websocket-dotnet/issues/34