ODP.Net .NET Core 5.0 上的驱动程序抛出异常
ODP.Net Driver Throwing Exception on .NET Core 5.0
我正在尝试将我的数据库应用程序从 .NET Core 3.1 移植到 .NET Core 5.0。
当运行以下代码时,
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();
}
}
我得到这个异常:
"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"
是否可以通过我的应用程序解决此问题?
我使用的是 Oracle.ManagedDataAccess.Core 2.19.91 的最新版本,发布于 2020 年 10 月 22 日。另外,我正在使用 Dapper 2.0.35.
我发现 Oracle 正在对此进行修复,应该很快就会可用。
同时,万一有人遇到这个问题,有一个解决方法。
在您的项目文件中,您可以将 XML 语句添加到 EnableUnsafeBinaryFormatterSerialization。
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
</PropertyGroup>
我正在尝试将我的数据库应用程序从 .NET Core 3.1 移植到 .NET Core 5.0。
当运行以下代码时,
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();
}
}
我得到这个异常:
"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"
是否可以通过我的应用程序解决此问题?
我使用的是 Oracle.ManagedDataAccess.Core 2.19.91 的最新版本,发布于 2020 年 10 月 22 日。另外,我正在使用 Dapper 2.0.35.
我发现 Oracle 正在对此进行修复,应该很快就会可用。
同时,万一有人遇到这个问题,有一个解决方法。
在您的项目文件中,您可以将 XML 语句添加到 EnableUnsafeBinaryFormatterSerialization。
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
</PropertyGroup>