dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.26k stars 4.73k forks source link

[dotnet-sdk-9.0.100-preview.3.24160.1] Freesql error: Ambiguous match found for 'System.TimeSpan System.TimeSpan FromSeconds(Int64)'. #99588

Closed Junjun-zhao closed 7 months ago

Junjun-zhao commented 8 months ago

Description

When running 3rd party application with the latest .NET 9 build, it stops working after launching. After investigation, we found it is caused by FreeSql. The exception from Visual Studio output window is: Ambiguous match found for 'System.TimeSpan System.TimeSpan FromSeconds(Int64)'.

Reproduction Steps

Minimal Repro steps (Demo attached:ConsoleDemo.zip): 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"
    }
  1. 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)'.

Regression?

Yes Verify Scenarios: 1). Windows 10 21H2 AMD64 + dotnet-sdk-8.0.101: Pass 2). Windows 10 21H2 AMD64 + dotnet-sdk-9.0.100-preview.2.24129.7: Pass 3). Windows 10 21H2 AMD64 + dotnet-sdk-9.0.100-preview.3.24160.1: Fail

Known Workarounds

No response

Configuration

Application Name: EasyCMS,CastIt,HyggeImaotai OS: Windows 10 21H2 CPU: X64 .NET Build Number: dotnet-sdk-9.0.100-preview.3.24160.1 App & Source Location checking at: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1992393 Github Link: https://github.com/yushuo1990/EasyCMS https://github.com/Wolfteam/CastIt https://github.com/lisongkun/HyggeImaotai

Other information

Dotnet Info:

.NET SDK:
Version:           9.0.100-preview.3.24160.1
Commit:            232d2df252
Workload version:  9.0.100-manifests.9f73df61
MSBuild version:   17.10.0-preview-24127-03+6f44380e4

Runtime Environment:
OS Name:     Windows
OS Version:  10.0.19045
OS Platform: Windows
RID:         win-x64
Base Path:   C:\Program Files\dotnet\sdk\9.0.100-preview.3.24160.1\

 .NET workloads installed:

There are no installed workloads to display.

 Host:

  Version:      9.0.0-preview.3.24157.12
  Architecture: x64
  Commit:       da781b3aab

 .NET SDKs installed:

  9.0.100-preview.3.24160.1 [C:\Program Files\dotnet\sdk]

 .NET runtimes installed:

  Microsoft.AspNetCore.App 9.0.0-preview.3.24157.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 9.0.0-preview.3.24157.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 9.0.0-preview.3.24158.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

@dotnet-actwx-bot @dotnet/compat

stephentoub commented 8 months ago

This is a 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

Junjun-zhao commented 7 months ago

This is a 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

Thank you @stephentoub for looking into this issue so quickly. We've filed an Freesql issue to notify the owner about this issue. Closing this issue.

2881099 commented 7 months ago

FreeSql.3.2.816-preview20240314