2023年12月22日 星期五

[研究][ASP.NET]ClosedXML 的 OpenXml 從 2.20.0 升級 3.0.0 成功,執行失敗

[研究][ASP.NET]ClosedXML 的 OpenXml 從 2.20.0 升級 3.0.0 成功,執行失敗

[研究][ASP.NET]找不到方法: 'DocumentFormat.OpenXml.OpenXmlElementList DocumentFormat.OpenXml.OpenXmlElement.get_ChildElements()'。

2023-12-22、2024-02-26更新

環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C# + ClosedXML

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

(下圖) Click 可看 100% 圖

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

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

找不到方法: 'DocumentFormat.OpenXml.OpenXmlElementList DocumentFormat.OpenXml.OpenXmlElement.get_ChildElements()'。

描述: 在執行目前 Web 要求的過程中發生未處理的例外狀況。請檢閱堆疊追蹤以取得錯誤的詳細資訊,以及在程式碼中產生的位置。

例外狀況詳細資訊: System.MissingMethodException: 找不到方法: 'DocumentFormat.OpenXml.OpenXmlElementList DocumentFormat.OpenXml.OpenXmlElement.get_ChildElements()'。

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

Method not found: 'DocumentFormat.OpenXml.OpenXmlElementList DocumentFormat.OpenXml.OpenXmlElement.get_ChildElements()'. #1608
https://github.com/dotnet/Open-XML-SDK/issues/1608

Migration to v3.0.0
https://learn.microsoft.com/en-us/office/open-xml/migration/migrate-v2-to-v3

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

參考

https://github.com/dotnet/Open-XML-SDK/issues/1608

實際測試發現是 NuGet 把 DocumentFormat.OpenXml 從 2.20.0 升級到 3.0.0 後發生問題, DocumentFormat.OpenXml.Framework 可以維持 3.0.0,不放心就一起也降到 2.20.0

檢查 packages.config 可知目前版本,

  <package id="DocumentFormat.OpenXml" version="3.0.0" targetFramework="net48" />
  <package id="DocumentFormat.OpenXml.Framework" version="3.0.0" targetFramework="net48" />

降版後是

  <package id="DocumentFormat.OpenXml" version="2.20.0" targetFramework="net48" />
  <package id="DocumentFormat.OpenXml.Framework" version="2.20.0" targetFramework="net48" />

實際測試,把 DocumentFormat.OpenXml.Framework 移除也正常運作。

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

請問 DocumentFormat.OpenXml 和 DocumentFormat.OpenXml.Framework 套件差異,後者必須存在嗎 ?

ChatGPT

截至我最後一次更新知識庫的時間(2022年1月),並沒有關於DocumentFormat.OpenXml.Framework的明確資訊。然而,根據我了解的情況,DocumentFormat.OpenXml是一個用於處理Office文件(如Word、Excel和PowerPoint)的.NET程式庫,而DocumentFormat.OpenXml.Framework則可能是一個與OpenXml相關的框架或工具集。

如果你遇到DocumentFormat.OpenXml.Framework的問題,建議檢查官方文檔或相關資源,以獲得最新的資訊。通常來說,開發人員使用DocumentFormat.OpenXml來處理Open XML文件,而Framework可能是一些附加的工具或支援額外功能的套件。確保查閱官方文檔以確定如何正確使用這些套件。

請注意,.NET生態系統中的套件和工具可能會經常更新,因此建議查看官方文檔或相關社群以獲取最新的資訊。

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

Open XML SDK 的最近更新
[3.0.0] - 2023-11-15
https://learn.microsoft.com/zh-cn/office/open-xml/what-s-new-in-the-open-xml-sdk
https://learn.microsoft.com/zh-tw/office/open-xml/what-s-new-in-the-open-xml-sdk

  • 核心基礎結構現在包含在新的套件DocumentFormat.OpenXml.Framework 中。類型化類別仍位於DocumentFormat.OpenXml 中。這意味著,可以引用DocumentFormat.OpenXml,但仍編譯相同的類型,但如果想要較小的套件,可以只依賴框架包。
  • 減少了DocumentFormat.OpenXml.Framework (#1471) 以外的套件的不必要的目標框架

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

2024-02-26 補

想要測試撰寫 ClosedXML 0.102.2 + DocumentFormat.OpenXml 3.0.0 的程式,發現 NuGet 安裝 ClosedXML 0.102.2 最新版,預設搭配 DocumentFormat.OpenXml 2.16.0,升級到 3.0.0 或 3.0.1 時,被禁止了。去年底是可以升級,但是執行時會失敗;現在直接禁止升級,算是省了麻煩。

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

錯誤 無法解析相依性。'DocumentFormat.OpenXml 3.0.1' 與 'ClosedXML 0.102.2 條件約束: DocumentFormat.OpenXml (>= 2.16.0 && < 3.0.0)' 不相容。


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

(完)

相關


沒有留言:

張貼留言