'COULD NOT LOAD TYPE 'System.Security.Principal.WindowsImpersonationContext' from assembly 'mscorlib'
I'm creating an ASP.NET API Core application, to handle API services, which communicate to an Oracle Database.
At runtime, when the process tries to connect to the DB with a new Oracle Connection throught a DbContext ( Entity Framework) an unhandled error appears and forces the app to stop.
myDbContext.Database.Connection.Open();
This line causes the following error
System.TypeLoadException : 'Could not load type 'System.Security.Principal.WindowsImpersonationContext' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=xxx'.'
I had an old but similar project which used the same code and worked properly. The library used is the same for Oracle Connector : Oracle.ManagedDataAccess.EntityFramework
What I tried :
- Unistall - Reinstall Oracle.ManagedDataAccess.EntityFramework,
- same for other Oracle connector ( Oracle.ManagedDataAccess, Oracle.ManagedDataAccess.Core )
- Install System.Security.Principal
- Changing the target framework from 3.1 to 5
I went first to this page 'System.Security.Principal.WindowsImpersonationContext' from assembly 'mscorlib' error when trying to parse template with Razor Engine but did not find anything that could help me resolve this.
Solution 1:[1]
For dot net 6, I was getting the same exception. Only kept the package: Oracle.ManagedDataAccess.Core and removed all others related to oracle and it works.
Solution 2:[2]
Get rid of 'Oracle.ManagedDataAccess'. I had both 'Oracle.ManagedDataAccess' and 'Oracle.ManagedDataAccess.Core' installed. This issue is most likely caused because 'Oracle.ManagedDataAccess' is for .NET Framework and not .NET Core/.NET 6.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Marwa Eldawy |
Solution 2 | npineda |