gpt4 book ai didi

vb.net - 无法加载文件或程序集“DocumentFormat.OpenXml - 再次”

转载 作者:行者123 更新时间:2023-12-02 09:59:42 24 4
gpt4 key购买 nike

看来这个问题是一个非常流行的问题,我已经阅读了近十几个类似的问题,但都提供了相同的解决方案(安装并引用 DocumentFormat.OpenXml 2.5),我已经这样做了,它是仍然无法工作。

我正在使用 Visual Studio 2012,在我的项目中引用 ClosedXML 版本 0.93 及其依赖项 DocumentFormat.OpenXML 版本 2.5。这两个 .dll 文件都存储在我的项目的 .exe 文件旁边。 Visual Studio 似乎看到了这些引用:

enter image description here

在我的代码顶部,我还有:

Imports DocumentFormat.OpenXml
Imports ClosedXML

但是,当我调用一个简单的测试代码时,

Dim workbook = New ClosedXML.Excel.XLWorkbook()
Dim worksheet = workbook.Worksheets.Add("Sample Sheet")
worksheet.Cell("A1").Value = "Hello World!"
workbook.SaveAs("HelloWorld.xlsx")

我收到错误消息:

An unhandled exception of type 'System.IO.FileLoadException' occurred in System.Windows.Forms.dll

Additional information: Could not load file or assembly 'DocumentFormat.OpenXml, Version=2.7.2.0, Culture=neutral, PublicKeyToken=8fb06cb64d019a17' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

我不知道为什么会发生这个错误。如果我写DocumentFormat.OpenXml。在我的代码中,我获得了该库中建议函数的列表,因此必须正确加载引用。

请问有人可以帮忙吗?

最佳答案

您是否注意到,在屏幕截图中,您在 OpenXml 程序集的引用中使用了版本 2.5,但异常消息引用了较新的 2.7.2?这可能是你的问题。可能您已经引用了 2.5,但“ClosedXML”期待 2.7.2,当它找不到时就会抛出错误?

我会获取 2.7.2,更新您的引用,然后看看是否有效。

关于vb.net - 无法加载文件或程序集“DocumentFormat.OpenXml - 再次”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50238486/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com