Bug #113453 OpenAsync of MySqlConnection cannot be used in .net framework
Submitted: 18 Dec 2023 20:08 Modified: 26 Jan 2024 9:41
Reporter: Ryousuke Tanida Email Updates:
Status: No Feedback Impact on me:
None 
Category:MySQL Server: C API (client library) Severity:S1 (Critical)
Version:8.2.0 OS:Windows
Assigned to: MySQL Verification Team CPU Architecture:Any

[18 Dec 2023 20:08] Ryousuke Tanida
Description:
OpenAsync of MySqlConnection cannot be used in .NetFramework.
If used, a TypeInitializationException will be thrown because "System.Runtime.Loader.AssemblyLoadContext" cannot be loaded from the assembly.
AssemblyLoadContext is only available in .NetCore and cannot be used in .NetFramework.
Is this a bug?
Or have the specifications changed so that the library cannot be used with .NetFramework?

How to repeat:
var cts = new CancellationTokenSource();
cts.CancelAfter(TimeSpan.FromSeconds(connectionTime));

DateTime preTime = DateTime.Now;
String connectionString="Server=servername;Database=databasename;Uid=idName;Pwd=passWord;Host=127.0.1;Pooling=True;Connection Lifetime=10;ConnectionTimeout=2;CharSet='utf8mb4'
var lc = Connection = new MySqlConnection(connectionString);
await lc.OpenAsync(cts.Token).ConfigureAwait(false);	//throw

Suggested fix:
If there is a problem, please fix it.
[18 Dec 2023 20:16] Ryousuke Tanida
I have confirmed that the exception is not thrown in version 8.0.32.1.
Later versions will throw an exception.
[19 Dec 2023 13:28] MySQL Verification Team
Hello Ryousuke Tanida,

Thank you for the bug report.
To investigate further this issue at our end, could you please provide exception details?

Regards,
Ashwini Patil
[19 Dec 2023 14:12] Ryousuke Tanida
Thank you for your reply.
The details of the exception are listed below.
Note that since there is only a Japanese execution environment, the exception output is in Japanese.

System.TypeInitializationException
  HResult=0x80131534
  Message='MySql.Data.MySqlClient.MySqlPoolManager' のタイプ初期化子が例外をスローしました。
  Source=MySql.Data
  スタック トレース:
   場所 MySql.Data.MySqlClient.MySqlPoolManager.get_Hosts()
   場所 MySql.Data.MySqlClient.MySqlConnection.<OpenAsync>d__94.MoveNext()
   場所 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   場所 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   場所 System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
   場所 FlowLib.MySqlEx.MySqlClient.<Connect>d__144.MoveNext() (F:\プログラム\FW\FlowLib\MySqlEx\MySqlClient.cs):行 984

  この例外は、最初にこの呼び出し履歴  でスローされました

内部例外 1:
TypeLoadException: アセンブリ 'System.Runtime.Loader, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' から型 'System.Runtime.Loader.AssemblyLoadContext' を読み込めませんでした。
[22 Dec 2023 6:22] Ryousuke Tanida
Hello.
Could you please check the contents of the exception you sent?
I would appreciate it if you could let me know if the content is insufficient.
Best regards,
[22 Dec 2023 12:46] MySQL Verification Team
Hello Ryousuke Tanida,

Thank you for the details.
I tried to reproduce your issue on windows 11 with the test case provided but I am seeing a different exception. Could you please provide complete repeatable test case?

Regards,
Ashwini Patil
[22 Dec 2023 14:22] Ryousuke Tanida
Hello. Ashwini Patil.

If source code is required to reproduce the issue, it will be included in the bug report.
What you need is the running project file itself?
The project file cannot be passed because it contains code that cannot be exposed externally.
If you have any other suggestions, please let us know.

thank you,
[26 Dec 2023 9:41] MySQL Verification Team
You can attach the test case using "Files" tab. Please make it as private if you prefer. Thanks.
[27 Jan 2024 1:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".