Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ODP.Net Driver Throwing Exception on .NET Core 5.0

I am trying to port my database application from .NET Core 3.1 to .NET Core 5.0.

When running the following code,

        public async Task<List<T>> LoadDataFromSQL<T, U>(string sql, U parameters, string connectionStringName)
        {
            using (IDbConnection connection = new OracleConnection(await GetConnectionString()))
            {
                var rows = await connection.QueryAsync<T>(sql,
                                                          parameters,
                                                          commandType: CommandType.Text);
                return rows.ToList();
            }
        } 

I get this exception:

"System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.\r\n ---> System.TypeInitializationException: The type initializer for 'OracleInternal.ServiceObjects.OracleConnectionImpl' threw an exception.\r\n ---> System.TypeInitializationException: The type initializer for 'Oracle.ManagedDataAccess.Types.TimeStamp' threw an exception.\r\n ---> System.NotSupportedException: BinaryFormatter serialization and deserialization are disabled within this application. See https://aka.ms/binaryformatter for more information.\r\n at OracleInternal.Common.OracleTimeZone.GetInstance()\r\n at Oracle.ManagedDataAccess.Types.TimeStamp..cctor()\r\n --- End of inner exception stack trace ---\r\n at Oracle.ManagedDataAccess.Types.TimeStamp.InitializelatestTZversion()\r\n at OracleInternal.ServiceObjects.OracleConnectionImpl..cctor()\r\n --- End of inner exception stack trace ---\r\n at OracleInternal.ServiceObjects.OracleConnectionImpl..ctor()\r\n --- End of inner except ion stack trace ---\r\n"

Is is possible to work around this from my application?

I am using the latest version of Oracle.ManagedDataAccess.Core 2.19.91, release on 10/22/2020. Also, I am using Dapper 2.0.35.

like image 845
Jason D Avatar asked Nov 11 '20 16:11

Jason D


People also ask

What is the difference between ODP core and ODP managed driver?

ODP.NET Core is designed for multi-platform .NET (Core) applications. ODP.NET, Managed Driver is 100% managed code .NET Framework provider. Developers deploy a single assembly in a deployment package smaller than 10 MB. ODP.NET, Unmanaged Driver is the traditional Oracle ADO.NET provider that uses the Oracle Database Client.

Does ODP support Entity Framework Core 5?

ODP.NET 21.3 supports user-defined types, Entity Framework Core 5, binary JSON data type, Client Initiated Continuous Query Notification, and more. Download ODP.NET as part of ODAC or download ODP.NET Core and Oracle Entity Framework Core on NuGet Gallery for multi-platform support.

What is ODP net in Oracle?

Oracle Data Provider for.NET (ODP.NET) features optimized ADO.NET data access to the Oracle database. ODP.NET allows developers to take advantage of advanced Oracle database functionality, including Real Application Clusters, self-tuning statement cache, Application Continuity, and Fast Connection Failover.

What are the different types of ODP drivers?

There are three driver types: ODP.NET Core; ODP.NET, Managed Driver; and ODP.NET, Unmanaged Driver. ODP.NET Core is designed for multi-platform .NET (Core) applications. ODP.NET, Managed Driver is 100% managed code .NET Framework provider. Developers deploy a single assembly in a deployment package smaller than 10 MB.


1 Answers

I discovered that Oracle is working on a fix for this which should be available soon.

In the meantime, in case anyone runs into this issue there is a workaround.

In your project file, you can add the XML statement to EnableUnsafeBinaryFormatterSerialization.

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
  </PropertyGroup>
like image 64
Jason D Avatar answered Oct 06 '22 21:10

Jason D