FileNotFoundException: Could not load file or assembly 'System.Configuration.ConfigurationManager,
Asked Answered
C

2

39

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?

Carpospore answered 27/1, 2020 at 16:52 Comment(6)
Try this : Go to project properties and uncheck prefer 32 bit.Haematocryal
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.Firth
alternatively , you can Install-Package System.Configuration.ConfigurationManager from nugetHaematocryal
"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.Belva
exactly same problem here when trying to connect to MySQLSpeakeasy
Installing the package doesn't help when deploying because the dll is not included in the buildAreola
H
51

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

Haematocryal answered 27/1, 2020 at 17:22 Comment(2)
For MySQL I needed this ,and also System.Management, no idea why.Speakeasy
Install-Package Oracle.ManagedDataAccess.Core instead System.Configuration.ConfigurationManager. It is deprecatedElbowroom
W
0

I tried adding a reference to NuGet package System.Configuration.ConfigurationManager, but the latest version of this library (7.0) doesn't contain the ConfigurationManager anymore. So then it still doesn't compile. After a lot of seaching, I figured out I had to include version 4.5 of the NuGet package.

Workday answered 10/1, 2023 at 10:2 Comment(2)
I just double check using dotPeek, the dll version 7.0.0.0 for .NETCoreApp v.6.0 indeed contains the class ConfigurationManager.Parmenter
I tried 7.0, no good, downgraded to 4.5, success! Thanks!Polymerism

© 2022 - 2024 — McMap. All rights reserved.