2026年4月14日 星期二

[研究]System.ValueTuple 4.5.0 升級到 4.6.x 後執行出錯

[研究]System.ValueTuple 4.5.0 升級到 4.6.x 後執行出錯

2025-04-14

環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C# + SQL Server 2019 + SQL Server Management Studio (SSMS) 20.2

********************************************************************************

ASP.NET WebForm Web Application 專案 System.ValueTuple 4.5.0 升級到 4.6.x 後,編譯成功,執行匯出會錯誤,出現

'/' 應用程式中發生伺服器錯誤。
無法載入檔案或組件 'System.ValueTuple, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' 或其相依性的其中之一。 系統找不到指定的檔案。
描述: 在執行目前 Web 要求的過程中發生未處理的例外狀況。請檢閱堆疊追蹤以取得錯誤的詳細資訊,以及在程式碼中產生的位置。

例外狀況詳細資訊: System.IO.FileNotFoundException: 無法載入檔案或組件 'System.ValueTuple, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' 或其相依性的其中之一。 系統找不到指定的檔案。

原始程式錯誤:


行 284:        catch (Exception)
行 285:        {
行 286:            throw;
行 287:        }
行 288:    }

原始程式檔: C:\Temp5\\Solution\WebApplication\Admin\Logs.aspx.cs    行: 286

堆疊追蹤:


[FileNotFoundException: 無法載入檔案或組件 'System.ValueTuple, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' 或其相依性的其中之一。 系統找不到指定的檔案。]
   SixLabors.Fonts.StreamFontMetrics..ctor(TrueTypeFontTables tables) +0
   SixLabors.Fonts.StreamFontMetrics.LoadTrueTypeFont(FontReader reader) +892
   SixLabors.Fonts.FontCollection.AddImpl(Stream stream, CultureInfo culture, FontDescription& description) +92
   ClosedXML.Graphics.DefaultGraphicEngine.AddEmbeddedFont(FontCollection fontCollection) in /_/ClosedXML/Graphics/DefaultGraphicEngine.cs:258
   ClosedXML.Graphics.DefaultGraphicEngine..ctor(String fallbackFont) in /_/ClosedXML/Graphics/DefaultGraphicEngine.cs:69
   ClosedXML.Graphics.<>c.<.cctor>b__31_0() in /_/ClosedXML/Graphics/DefaultGraphicEngine.cs:55
   System.Lazy`1.CreateValue() +734
   System.Lazy`1.LazyInitValue() +189
   ClosedXML.Excel.XLWorkbook..ctor(LoadOptions loadOptions) in /_/ClosedXML/Excel/XLWorkbook.cs:784
   Admin_Logs.Button_Export_Xlsx_by_ClosedXML_Click(Object sender, EventArgs e) in C:\Temp5\\Solution\WebApplication\Admin\Logs.aspx.cs:286
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +138
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +150
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5445

版本資訊: Microsoft .NET Framework 版本:4.0.30319; ASP.NET 版本:4.8.4797.0

**********

ChatGPT   

Web.Config 出錯


<dependentAssembly> <assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" /> </dependentAssembly>

改為


<dependentAssembly> <assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.0.7.0" newVersion="4.0.7.0" /> </dependentAssembly>


執行 Update-Package System.ValueTuple -Reinstall


因為

Package Version Assembly Version
4.5.x 4.0.3.0
4.6.x 4.0.4.0~4.0.7.0

⚠️ ClosedXML 0.105 + SixLabors.Fonts 1.0.1

這組合有 2 個問題:

❌ 問題 1

SixLabors.Fonts 1.0.1 很舊

→ .NET Framework binding 相容性不好

❌ 問題 2

ClosedXML 0.105 在 Graphics engine 會強制載入 font engine

→ 直接觸發 ValueTuple load chain

**********

編譯成功,但有警告

已開始重建...

1>------ 已開始全部重建: 專案: WebApplication1, 組態: Debug Any CPU ------

1>  請考慮將組件 "System.ValueTuple, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" 的 app.config 從版本 "4.0.3.0" [C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\System.ValueTuple.dll] 重新對應至版本 "4.0.5.0" [C:\Git\Solution1\WebApplication1\packages\System.ValueTuple.4.6.2\lib\net47\System.ValueTuple.dll],以解決衝突並避免出現警告。

1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2203,5): warning MSB3247: 在同一個相依組件的不同版本之間發現衝突。請在 Visual Studio 中按兩下這個警告 (或選取後按 Enter) 解決這些衝突,或者將下列繫結重新導向加到應用程式組態檔中的 [執行階段] 節點: <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="System.ValueTuple" culture="neutral" publicKeyToken="cc7b13ffcd2ddd51" /><bindingRedirect oldVersion="0.0.0.0-4.0.5.0" newVersion="4.0.5.0" /></dependentAssembly></assemblyBinding>

1>  WebApplication1 -> C:\Git\Solution1\WebApplication1\WebApplication1\bin\WebApplication1.dll

2>------ 已開始全部重建: 專案: WebApplication1.Tests, 組態: Debug Any CPU ------

2>  請考慮將組件 "System.ValueTuple, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" 的 app.config 從版本 "4.0.3.0" [C:\Git\Solution1\WebApplication1\WebApplication1\bin\System.ValueTuple.dll] 重新對應至版本 "4.0.5.0" [C:\Git\Solution1\WebApplication1\packages\System.ValueTuple.4.6.2\lib\net47\System.ValueTuple.dll],以解決衝突並避免出現警告。

2>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2203,5): warning MSB3247: 在同一個相依組件的不同版本之間發現衝突。請在 Visual Studio 中按兩下這個警告 (或選取後按 Enter) 解決這些衝突,或者將下列繫結重新導向加到應用程式組態檔中的 [執行階段] 節點: <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="System.ValueTuple" culture="neutral" publicKeyToken="cc7b13ffcd2ddd51" /><bindingRedirect oldVersion="0.0.0.0-4.0.5.0" newVersion="4.0.5.0" /></dependentAssembly></assemblyBinding>

2>  WebApplication1.Tests -> C:\Git\Solution1\WebApplication1\WebApplication1.Tests\bin\Debug\WebApplication1.Tests.dll

========== 全部重建: 2 成功、0 失敗、 0 略過 ==========


========== 全部重建: 2 成功、0 失敗、 0 略過 ==========

、、、、略,ChatGPT 又說要改回 4.0.5.0,然後又重複相同問題。

(待續)

相關

沒有留言:

張貼留言