dotnetcore / FreeSql

🦄 .NET aot orm, C# orm, VB.NET orm, Mysql orm, Postgresql orm, SqlServer orm, Oracle orm, Sqlite orm, Firebird orm, 达梦 orm, 人大金仓 orm, 神通 orm, 翰高 orm, 南大通用 orm, 虚谷 orm, 国产 orm, Clickhouse orm, DuckDB orm, TDengine orm, QuestDB orm, MsAccess orm.
https://dotnetcore.github.io/FreeSql/
MIT License
4.11k stars 857 forks source link

Freesql error: Ambiguous match found for 'System.TimeSpan System.TimeSpan FromSeconds(Int64)' with the latest .NET 9.0.100-preview.3.24160.1 #1748

Closed CancanTang closed 1 month ago

CancanTang commented 7 months ago

问题描述

When we create console project to using Freesql package with the latest .NET 9 build, it stops working after launching. The exception from Visual Studio output window is: Ambiguous match found for 'System.TimeSpan System.TimeSpan FromSeconds(Int64)'. After investigating we found the bug in the FreeSql library. This line is expecting there to only be one overload of TimeSpan.FromSeconds, but there are now multiple overloads, which leads to GetMethod throwing an ambiguity exception because it doesn't know which method to bind to: https://github.com/dotnetcore/FreeSql/blob/e1f91ef361ca4a6eac7f217bd4a474047597e4e3/FreeSql/Internal/UtilsExpressionTree.cs#L2172

重现代码

The machine has dotnet-sdk-9.0.100-preview.3.24160.1 installed. 1.Create a new net8.0 Console project. 2.Copy the following code to Program.cs.

using FreeSql;
string ConnetionString = "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=Demo;";
var freeBuilder = new FreeSqlBuilder().UseConnectionString(DataType.SqlServer, ConnetionString).Build();
Console.WriteLine(freeBuilder);

3.Install FreeSql.Provider.SqlServer nuget package. 4.Build the app. 5.Change the runtime.config file to let the app run against with dotnet-sdk-9.0.100-preview.3.24160.1.

 "framework": {
      "name": "Microsoft.NETCore.App",
      "version": "9.0.0-preview.3.24157.12"
    }

6.Launch the app.

Expected behavior Launch successfully.

Actual behavior

System.TypeInitializationException: 'The type initializer for 'FreeSql.Internal.Utils' threw an exception.'
AmbiguousMatchException: Ambiguous match found for 'System.TimeSpan System.TimeSpan FromSeconds(Int64)'.

For more detailed bug info you can veiw : https://github.com/dotnet/runtime/issues/99588

数据库版本

Microsoft SQL Server 2019 LocalDB

安装的Nuget包

FreeSql.Provider.SqlServer 3.2.815

.net framework/. net core? 及具体版本

dotnet-sdk-9.0.100-preview.3.24160.1

2881099 commented 7 months ago

这么快就用.net9了啊

CancanTang commented 7 months ago

Thank you for fixing the issue so quickly, it works with FreeSql.3.2.816-preview20240314.