2026年4月15日 星期三

[研究]ClosedXML 0.105.0 是否相依 System.ValueTuple 測試(二)

[研究]ClosedXML 0.105.0 是否相依 System.ValueTuple 測試(二)

2025-04-15

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

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

[研究]System.ValueTuple 4.5.0 升級到 4.6.x 後執行出錯
https://shaurong.blogspot.com/2026/04/systemvaluetuple-450-46x.html
根據這篇,ChatGPT 說 ClosedXML 0.105 在 Graphics engine 會強制載入 font engine,直接觸發 ValueTuple load chain

[研究]ClosedXML 0.105.0 是否相依 System.ValueTuple 測試
https://shaurong.blogspot.com/2026/04/closedxml-01050-systemvaluetuple.html
根據這篇,沒有 ValueTuple

此測試用 NuGet 多安裝了 System.ValueTuple 4.6.2

**********

packages.config


<?xml version="1.0" encoding="utf-8"?> <packages> <package id="ClosedXML" version="0.105.0" targetFramework="net48" /> <package id="ClosedXML.Parser" version="2.0.0" targetFramework="net48" /> <package id="DocumentFormat.OpenXml" version="3.5.1" targetFramework="net48" /> <package id="DocumentFormat.OpenXml.Framework" version="3.5.1" targetFramework="net48" /> <package id="ExcelNumberFormat" version="1.1.0" targetFramework="net48" /> <package id="Microsoft.Bcl.HashCode" version="6.0.0" targetFramework="net48" /> <package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="4.1.0" targetFramework="net48" /> <package id="RBush.Signed" version="4.0.0" targetFramework="net48" /> <package id="SixLabors.Fonts" version="1.0.1" targetFramework="net48" /> <package id="System.Buffers" version="4.6.1" targetFramework="net48" /> <package id="System.Memory" version="4.6.3" targetFramework="net48" /> <package id="System.Numerics.Vectors" version="4.6.1" targetFramework="net48" /> <package id="System.Runtime.CompilerServices.Unsafe" version="6.1.2" targetFramework="net48" /> <package id="System.ValueTuple" version="4.6.2" targetFramework="net48" /> </packages>

Default.aspx


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1.Default" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> </head> <body> <form id="form1" runat="server"> <asp:Button ID="btnExport" runat="server" Text="匯出 Excel" OnClick="btnExport_Click" /> </form> </body> </html>

Default.aspx.cs


using ClosedXML.Excel; using System; using System.Data; using System.IO; namespace WebApplication1 { public partial class Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnExport_Click(object sender, EventArgs e) { // 建立測試資料 DataTable dt = GetSampleData(); using (XLWorkbook wb = new XLWorkbook()) { var ws = wb.Worksheets.Add(dt, "Sheet1"); // 設定樣式 ws.Columns().AdjustToContents(); ws.Row(1).Style.Font.Bold = true; // 輸出 Response.Clear(); Response.Buffer = true; Response.Charset = ""; Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; Response.AddHeader("content-disposition", "attachment;filename=Export.xlsx"); using (MemoryStream ms = new MemoryStream()) { wb.SaveAs(ms); ms.WriteTo(Response.OutputStream); Response.Flush(); Response.End(); } } } private DataTable GetSampleData() { DataTable dt = new DataTable(); dt.Columns.Add("ID", typeof(int)); dt.Columns.Add("姓名", typeof(string)); dt.Columns.Add("日期", typeof(DateTime)); dt.Columns.Add("金額", typeof(decimal)); dt.Rows.Add(1, "王小明", DateTime.Now, 1000); dt.Rows.Add(2, "李小華", DateTime.Now.AddDays(-1), 2000); dt.Rows.Add(3, "陳小美", DateTime.Now.AddDays(-2), 3000); return dt; } } }

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

Deploy 後實際測試



執行時期沒有發生錯誤,看起來正常。
ClosedXML 0.105 在 Graphics engine 會強制載入 font engine,直接觸發 ValueTuple load chain 的情況,此測試中沒有發生,或是 ChatGPT 的說法有問題???

(完)

相關

[研究] Adobe Acrobat Reader DC 2026.001.21431繁體中文版 離線安裝版 下載地點 x86 x64

[研究] Adobe Acrobat Reader DC 2026.001.21431 繁體中文版 離線安裝版 下載地點 x86 x64

2026-04-15

線上安裝版下載

https://get.adobe.com/tw/reader/


Adobe Acrobat Reader DC 2026.001.21431 繁體中文版 離線安裝版 下載地點 x86 (此處不提供 x64版)

https://get.adobe.com/tw/reader/enterprise

https://ardownload3.adobe.com/pub/adobe/reader/win/AcrobatDC/2600121431/AcroRdrDC2600121431_zh_TW.exe


Adobe Acrobat Reader DC 2025.0012.20997 繁體中文版 離線安裝版 下載地點 x64

https://ardownload2.adobe.com/pub/adobe/acrobat/win/AcrobatDC/2500120997/AcroRdrDCx642500120997_zh_TW.exe

(完)

2026年4月14日 星期二

[研究]ClosedXML 0.105.0 是否相依 System.ValueTuple 測試

[研究]ClosedXML 0.105.0 是否相依 System.ValueTuple 測試

2025-04-07

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

續這篇

[研究]System.ValueTuple 4.5.0 升級到 4.6.x 後執行出錯
https://shaurong.blogspot.com/2026/04/systemvaluetuple-450-46x.html

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

NuGet 安裝ClosedXML 0.105.0

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

WebApplication1

正在安裝:

DocumentFormat.OpenXml.Framework.3.1.1

DocumentFormat.OpenXml.3.1.1

ExcelNumberFormat.1.1.0

Microsoft.Bcl.HashCode.1.1.1

RBush.Signed.4.0.0

System.Buffers.4.5.1

System.Numerics.Vectors.4.5.0

System.Runtime.CompilerServices.Unsafe.4.7.0

System.Memory.4.5.5

ClosedXML.Parser.2.0.0

SixLabors.Fonts.1.0.0

ClosedXML.0.105.0

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

更新

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

WebApplication1

更新:

SixLabors.Fonts.1.0.0 -> SixLabors.Fonts.2.1.3

System.Memory.4.5.5 -> System.Memory.4.6.3

System.Runtime.CompilerServices.Unsafe.4.7.0 -> System.Runtime.CompilerServices.Unsafe.6.1.2

System.Numerics.Vectors.4.5.0 -> System.Numerics.Vectors.4.6.1

System.Buffers.4.5.1 -> System.Buffers.4.6.1

Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1 -> Microsoft.CodeDom.Providers.DotNetCompilerPlatform.4.1.0

Microsoft.Bcl.HashCode.1.1.1 -> Microsoft.Bcl.HashCode.6.0.0

DocumentFormat.OpenXml.3.1.1 -> DocumentFormat.OpenXml.3.5.1

DocumentFormat.OpenXml.Framework.3.1.1 -> DocumentFormat.OpenXml.Framework.3.5.1

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

下面,編譯失敗

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

嚴重性 程式碼 說明 專案 檔案 隱藏項目狀態

錯誤 無法安裝封裝 'SixLabors.Fonts 2.1.3'。您正嘗試將此封裝安裝到以 '.NETFramework,Version=v4.8' 為目標的專案,但該封裝不包含任何與架構相容的組件參考或內容檔。如需詳細資訊,請連絡封裝作者。

********************************************************************************
SixLabors.Fonts 2.1.3 不支援 .NET Framework 4.8(或沒有提供可用的 compatible assets)

********************************************************************************
不要升級 SixLabors.Fonts 2.1.3,其他再升級一次
********************************************************************************

WebApplication1

更新:

System.Memory.4.5.5 -> System.Memory.4.6.3

System.Runtime.CompilerServices.Unsafe.4.7.0 -> System.Runtime.CompilerServices.Unsafe.6.1.2

System.Numerics.Vectors.4.5.0 -> System.Numerics.Vectors.4.6.1

System.Buffers.4.5.1 -> System.Buffers.4.6.1

Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1 -> Microsoft.CodeDom.Providers.DotNetCompilerPlatform.4.1.0

Microsoft.Bcl.HashCode.1.1.1 -> Microsoft.Bcl.HashCode.6.0.0

DocumentFormat.OpenXml.3.1.1 -> DocumentFormat.OpenXml.3.5.1

DocumentFormat.OpenXml.Framework.3.1.1 -> DocumentFormat.OpenXml.Framework.3.5.1

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

packages.config


<?xml version="1.0" encoding="utf-8"?> <packages> <package id="ClosedXML" version="0.105.0" targetFramework="net48" /> <package id="ClosedXML.Parser" version="2.0.0" targetFramework="net48" /> <package id="DocumentFormat.OpenXml" version="3.5.1" targetFramework="net48" /> <package id="DocumentFormat.OpenXml.Framework" version="3.5.1" targetFramework="net48" /> <package id="ExcelNumberFormat" version="1.1.0" targetFramework="net48" /> <package id="Microsoft.Bcl.HashCode" version="6.0.0" targetFramework="net48" /> <package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="4.1.0" targetFramework="net48" /> <package id="RBush.Signed" version="4.0.0" targetFramework="net48" /> <package id="SixLabors.Fonts" version="1.0.0" targetFramework="net48" /> <package id="System.Buffers" version="4.6.1" targetFramework="net48" /> <package id="System.Memory" version="4.6.3" targetFramework="net48" /> <package id="System.Numerics.Vectors" version="4.6.1" targetFramework="net48" /> <package id="System.Runtime.CompilerServices.Unsafe" version="6.1.2" targetFramework="net48" /> </packages>

並沒有用到  System.ValueTuple 

(完)

相關

[研究]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,然後又重複相同問題。

(待續)

相關