oracleodp.net-managed.net-5

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.


Solution

  • 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>