問題描述
我正在嘗試將我的數據庫應用程序從 .NET Core 3.1 移植到 .NET Core 5.0.
I am trying to port my database application from .NET Core 3.1 to .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: 調用的目標已拋出異常.\r\n --->System.TypeInitializationException: 'OracleInternal.ServiceObjects.OracleConnectionImpl' 的類型初始值設定項引發異常.\r\n --->System.TypeInitializationException: 'Oracle.ManagedDataAccess.Types.TimeStamp' 的類型初始值設定項引發異常.\r\n --->System.NotSupportedException:此應用程序中禁用了 BinaryFormatter 序列化和反序列化.有關詳細信息,請參閱 https://aka.ms/binaryformatter.\r\n 在 OracleInternal.Common.OracleTimeZone.GetInstance()\r\n 在 Oracle.ManagedDataAccess.Types.TimeStamp..cctor()\r\n --- 內部異常堆棧跟蹤結束 ---\r\n 在 Oracle.ManagedDataAccess.Types.TimeStamp.InitializelatestTZversion()\r\n 在 OracleInternal.ServiceObjects.OracleConnectionImpl..cctor()\r\n --- 內部異常堆棧跟蹤結束 ---\r\n 在 OracleInternal.ServiceObjects.OracleConnectionImpl..ctor()\r\n --- 內部結束,除了離子堆棧跟蹤 ---\r\n"
"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?
我使用的是最新版本的 Oracle.ManagedDataAccess.Core 2.19.91,發布于 2020 年 10 月 22 日.另外,我使用的是 Dapper 2.0.35.
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.
推薦答案
我發現 Oracle 正在為此進行修復,該修復應該很快就會推出.
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.
在您的項目文件中,您可以將 XML 語句添加到 EnableUnsafeBinaryFormatterSerialization.
In your project file, you can add the XML statement to EnableUnsafeBinaryFormatterSerialization.
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
</PropertyGroup>
這篇關于ODP.Net 驅動程序在 .NET Core 5.0 上拋出異常的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!