顯示具有 System.ValueTuple 標籤的文章。 顯示所有文章
顯示具有 System.ValueTuple 標籤的文章。 顯示所有文章

2026年8月11日 星期二

[研究]解決 System.ValueTuple 4.5.0 升級 4.6.1 或 4.6.2 問題

[研究]解決 System.ValueTuple 4.5.0 升級 4.6.1 或 4.6.2 問題

2025-08-07
2025-08-12 更新

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

NuGet 升級後,Compile 和 Deploy 都正常,Runtime 出錯


xxx

'/' 應用程式中發生伺服器錯誤。

無法載入檔案或組件 '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:    }



堆疊追蹤:

[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() +243
   System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +32
   System.Lazy`1.get_Value() +14443164
   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:\Git\Solution1\WebApplication1\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


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

根本問題在於 Visual Studio 2019 沒有把 4.6.x 版 System.ValueTuple.dll 拷貝到 bin 目錄 ( 4.5.0 時代會拷貝),

先用 NuGet 把 4.5.0 升級為 4.6.2

確認新、舊版,PowerShell 指令如下


PS C:\Users\Administrator> [System.Reflection.AssemblyName]::GetAssemblyName("D:\Production\OT\Web\bin\System.ValueTuple.dll").FullName System.ValueTuple, Version=4.0.5.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 PS C:\Users\Administrator>

把 Web.Config 中,類似

<configuration>
<runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

<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>

改寫為

<configuration>
<runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

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

改為

*****

把 .csproj 檔案中


<Reference Include="System.ValueTuple" />

改為


<Reference Include="System.ValueTuple"> <HintPath>..\packages\System.ValueTuple.4.6.2\lib\net47\System.ValueTuple.dll</HintPath> <Private>True</Private> </Reference>

即可。

(完)

相關

2026年5月5日 星期二

[研究]ASP.NET WebForm 整理會導致 System.ValueTuple 4.5.0 升級 4.6.x 的套件

[研究]ASP.NET WebForm 整理會導致 System.ValueTuple 4.5.0 升級 4.6.x 的套件

2026-05-05

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

AngleSharp 0.17.1 -> 1.4.0 不會

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

bootstrap 3.4.1 -> 5.3.8 不會

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

【Microsoft.ApplicationInsights.2.23.0 -> Microsoft.ApplicationInsights.3.1.0】


Microsoft.ApplicationInsights.2.23.0 -> Microsoft.ApplicationInsights.3.1.0

System.Text.Json.9.0.15 -> System.Text.Json.10.0.3

System.ValueTuple.4.5.0 -> System.ValueTuple.4.6.1


正在安裝:


OpenTelemetry.PersistentStorage.Abstractions.1.0.2

OpenTelemetry.PersistentStorage.FileSystem.1.0.2

Microsoft.Extensions.Primitives.10.0.3

Microsoft.Extensions.FileProviders.Abstractions.10.0.3

OpenTelemetry.Api.1.15.1

Microsoft.Extensions.Logging.Abstractions.10.0.3

OpenTelemetry.Api.ProviderBuilderExtensions.1.15.1

Microsoft.Extensions.Configuration.Abstractions.10.0.3

Microsoft.Extensions.Configuration.10.0.0

Microsoft.Extensions.Configuration.Binder.10.0.0

Microsoft.Extensions.Options.10.0.3

Microsoft.Extensions.Diagnostics.Abstractions.10.0.3

Microsoft.Extensions.Hosting.Abstractions.10.0.3

Microsoft.Extensions.Logging.10.0.0

Microsoft.Extensions.Options.ConfigurationExtensions.10.0.0

Microsoft.Extensions.Logging.Configuration.10.0.0

OpenTelemetry.1.15.1

OpenTelemetry.Extensions.Hosting.1.15.1

System.Memory.Data.10.0.3

System.ClientModel.1.10.0

Azure.Core.1.52.0

Azure.Monitor.OpenTelemetry.Exporter.1.7.0


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


【Microsoft.Bcl.Cryptography.9.0.15 -> Microsoft.Bcl.Cryptography.10.0.7】


Microsoft.Bcl.Cryptography.9.0.15 -> Microsoft.Bcl.Cryptography.10.0.7

System.Formats.Asn1.9.0.15 -> System.Formats.Asn1.10.0.7

System.ValueTuple.4.5.0 -> System.ValueTuple.4.6.2


更新:


Microsoft.Bcl.Cryptography.9.0.15 -> Microsoft.Bcl.Cryptography.10.0.7

System.Formats.Asn1.9.0.15 -> System.Formats.Asn1.10.0.7

System.ValueTuple.4.5.0 -> System.ValueTuple.4.6.2


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


NPOI 2.7.6 -> 2.8.0 不會

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


【RestSharp.112.1.0 -> RestSharp.113.0.0】

有時候會說

RestSharp.112.1.0 -> RestSharp.113.0.0

System.Text.Json.9.0.15 -> System.Text.Json.10.0.0

System.ValueTuple.4.5.0 -> System.ValueTuple.4.6.1

有時候只會說

RestSharp.112.1.0 -> RestSharp.113.0.0


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


【RestSharp.112.1.0 -> RestSharp.113.1.0】


RestSharp.112.1.0 -> RestSharp.113.1.0

System.Text.Json.9.0.15 -> System.Text.Json.10.0.0

System.ValueTuple.4.5.0 -> System.ValueTuple.4.6.1


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


【RestSharp.112.1.0 -> RestSharp.114.0.0】


RestSharp.112.1.0 -> RestSharp.114.0.0

System.Text.Json.9.0.15 -> System.Text.Json.10.0.0

System.ValueTuple.4.5.0 -> System.ValueTuple.4.6.1


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


SixLabors.Fonts 1.0.1 => 2.1.3 不會


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


某些 System. 開頭 9.x 版升級到 10.x 版就會導致


【System.Formats.Asn1.9.0.15 -> System.Formats.Asn1.10.0.7】


System.Formats.Asn1.9.0.15 -> System.Formats.Asn1.10.0.7

System.ValueTuple.4.5.0 -> System.ValueTuple.4.6.2


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


【Microsoft.Bcl.Cryptography.9.0.15 -> Microsoft.Bcl.Cryptography.10.0.7】


Microsoft.Bcl.Cryptography.9.0.15 -> Microsoft.Bcl.Cryptography.10.0.7

System.Formats.Asn1.9.0.15 -> System.Formats.Asn1.10.0.7

System.Security.Cryptography.Pkcs.9.0.15 -> System.Security.Cryptography.Pkcs.10.0.7

System.ValueTuple.4.5.0 -> System.ValueTuple.4.6.2


更新:


Microsoft.Bcl.Cryptography.9.0.15 -> Microsoft.Bcl.Cryptography.10.0.7

System.Formats.Asn1.9.0.15 -> System.Formats.Asn1.10.0.7

System.Security.Cryptography.Pkcs.9.0.15 -> System.Security.Cryptography.Pkcs.10.0.7

System.ValueTuple.4.5.0 -> System.ValueTuple.4.6.2



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


【Microsoft.Bcl.Cryptography.9.0.15 -> Microsoft.Bcl.Cryptography.10.0.7]


Microsoft.Bcl.Cryptography.9.0.15 -> Microsoft.Bcl.Cryptography.10.0.7

System.Formats.Asn1.9.0.15 -> System.Formats.Asn1.10.0.7

System.Security.Cryptography.Xml.9.0.15 -> System.Security.Cryptography.Xml.10.0.7

System.ValueTuple.4.5.0 -> System.ValueTuple.4.6.2


更新:


Microsoft.Bcl.Cryptography.9.0.15 -> Microsoft.Bcl.Cryptography.10.0.7

System.Formats.Asn1.9.0.15 -> System.Formats.Asn1.10.0.7

System.Security.Cryptography.Xml.9.0.15 -> System.Security.Cryptography.Xml.10.0.7

System.ValueTuple.4.5.0 -> System.ValueTuple.4.6.2


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


【System.Text.Encoding.CodePages.9.0.15 -> System.Text.Encoding.CodePages.10.0.7】


System.Text.Encoding.CodePages.9.0.15 -> System.Text.Encoding.CodePages.10.0.7

System.ValueTuple.4.5.0 -> System.ValueTuple.4.6.2


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


【System.Text.Json.9.0.15 -> System.Text.Json.10.0.7】


System.Text.Json.9.0.15 -> System.Text.Json.10.0.7

System.ValueTuple.4.5.0 -> System.ValueTuple.4.6.2


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

(待續)

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 的說法有問題???

(完)

相關

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

(待續)

相關

2025年5月15日 星期四

[研究]ASP.NET,無法載入檔案或組件 'System.ValueTuple

[研究]ASP.NET,無法載入檔案或組件 'System.ValueTuple

2025-05-15

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

目前使用 .NET Framework 4.8.0

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

Compile/Build、Deploy 正常,Runtime 執行某功能出現錯誤

無法載入檔案或組件 'System.ValueTuple, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' 或其相依性的其中之一。 系統找不到指定的檔案。"

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

把 System.ValueTuple.4.6.1 -> System.ValueTuple.4.5.0 退版,出現

HtmlSanitizer.9.0.884 -> HtmlSanitizer.9.0.876

System.ValueTuple.4.6.1 -> System.ValueTuple.4.5.0

它會自動退版2個。

Compile/Build、Deploy 正常,Runtime 執行某功能正常。

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

2025-05-16 補測試,安裝 HtmlSanitizer.9.0.884 和 System.ValueTuple 4.6.1 版

Web.Config 中設定為

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

測試依舊失敗

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

2025-05-16 補測試

Web.Config 中設定為

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

測試依舊失敗

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

2025-05-16 補測試

Web.Config 中拿掉類似下面的

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

編譯有警告

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" [],以解決衝突並避免出現警告。

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>

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

(完)

2025年4月28日 星期一

[研究]ASP.NET,HtmlSanitizer.9.0.876 升級 HtmlSanitizer.9.0.884 測試

[研究]ASP.NET,HtmlSanitizer.9.0.876 升級 HtmlSanitizer.9.0.884 測試

2025-04-28

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

因為某專案把HtmlSanitizer.9.0.876 升級 HtmlSanitizer.9.0.884 後,編譯 (重建方案) 有警告,而且發布 (Deploy) 後,居然無法運作,建立全新方案測試看看。

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

【遇到的問題】

已開始重建...

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" [],以解決衝突並避免出現警告。

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 -> D:\WebSolution1\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:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\System.ValueTuple.dll] 重新對應至版本 "4.0.5.0" [],以解決衝突並避免出現警告。

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 -> D:\WebSolution1\WebApplication1\WebApplication1.Tests\bin\Debug\WebApplication1.Tests.dll

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

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

【全新專案,NuGet 安裝 HtmlSanitizer.9.0.876】

WebApplication1

正在安裝:

System.Buffers.4.5.1

System.Numerics.Vectors.4.5.0

System.Runtime.CompilerServices.Unsafe.6.0.0

System.Memory.4.5.5

System.Collections.Immutable.9.0.1

System.Text.Encoding.CodePages.6.0.0

AngleSharp.0.17.1

AngleSharp.Css.0.17.0

HtmlSanitizer.9.0.876


【編譯正常】

已開始重建...

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

1>  WebApplication1 -> C:\WebSolution1\WebApplication1\WebApplication1\bin\WebApplication1.dll

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

********************************************************************************
【升級到 HtmlSanitizer.9.0.884】

WebApplication1

更新:

HtmlSanitizer.9.0.876 -> HtmlSanitizer.9.0.884

正在安裝:

System.ValueTuple.4.6.1

【編譯正常,沒有警告】

已開始重建...

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

1>  WebApplication1 -> C:\WebSolution1\WebApplication1\WebApplication1\bin\WebApplication1.dll

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

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

也就是原來方案的 Web.config 或 app.config 要添加或修改 System.ValueTuple 的一些設定。

(完)