【问题标题】:Could not load file or assembly 'Microsoft.mshtml, Version=7.0.3300.0无法加载文件或程序集“Microsoft.mshtml,版本=7.0.3300.0
【发布时间】:2019-10-25 07:19:30
【问题描述】:

我正在使用 Spire.pdf dll 静默打印 html 页面,它在我的机器上运行良好,但在客户端机器上出现以下错误。

System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.msht
ml, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one
of its dependencies. The system cannot find the file specified.
File name: 'Microsoft.mshtml, Version=7.0.3300.0, Culture=neutral, PublicKeyToke
n=b03f5f7f11d50a3a'
  at Spire.Pdf.HtmlConverter.HtmlConverter.?(String A_0, ImageType A_1, Int32 A
_2)
  at Spire.Pdf.HtmlConverter.HtmlConverter.Convert(String url, ImageType type,
Int32 width, Int32 height, AspectRatio aspectRatio)
  at Spire.Pdf.PdfSection.?(String A_0, Boolean A_1, Boolean A_2, Boolean A_3,
PdfHtmlLayoutFormat A_4)
  at Spire.Pdf.PdfDocument.LoadFromHTML(String htmlSourceCode, Boolean autoDete
ctPageBreak, PdfPageSettings setting, PdfHtmlLayoutFormat layoutFormat, Boolean
isLoadComplete)
  at Spire.Pdf.PdfDocument.LoadFromHTML(String htmlSourceCode, Boolean autoDete
ctPageBreak, PdfPageSettings setting, PdfHtmlLayoutFormat layoutFormat)
  at SP.Module1.Main() in D:\Nikhil\Project\PrintDocument\SP\Module1.vb:line 96


WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\M
icrosoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure lo
gging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fus
ion!EnableLog].

我查看下面的页面并尝试通过添加引用并将 dll 复制到 exe 所在的本地文件夹来引用 mshtml.dll,可能是我不完全了解如何使用它。

Could not load file or assembly 'Microsoft.mshtml ... Strong name validation failed

如果有人能告诉我如何在客户端机器上安装该 dll,下面是我正在使用的代码

                Dim doc As New PdfDocument()
                Dim pgSt As New PdfPageSettings()
                pgSt.Size = PdfPageSize.A4
                pgSt.SetMargins(0.5, 0.5, 0.5, 0.5)

                Dim htmlLayoutFormat As New PdfHtmlLayoutFormat()
                htmlLayoutFormat.IsWaiting = False


                ' Dim htmlpath As String = "D:\Print-code\test3.html"
                Dim source As String = response.Content ' File.ReadAllText(htmlpath)
                doc.LoadFromHTML(source, True, pgSt, htmlLayoutFormat)

                doc.PrintSettings.PrintController = New StandardPrintController()
                doc.PrintSettings.PrinterName = printer
                'doc.PrintSettings.Copies = 2
                'Print all pages with default printer
                doc.Print()

【问题讨论】:

  • 您似乎复制了错误的 DLL。请务必使用 C:\Windows\assembly\GAC\Microsoft.mshtml\7.0.3300.0__b03f5f7f11d50a3a\Microsoft.mshtml.dll。或者运行供应商的安装程序,它应该会处理它。
  • 汉斯你提到的文件路径在我的机器上不可用,我只有 C:\Windows\assembly\
  • 它在那里,Explorer 不会让你看到它,因为 shell 扩展会扁平化旧 GAC 的视图。从命令行执行此操作以取得成功。
  • @Hans 现在使用命令行我可以到达 C:\Windows\assembly\GAC\Microsoft.mshtml\7.0.3300.0__b03f5f7f11d50a3a\ 所以我只需要将 Microsoft.mshtml.dll 复制到我的本地文件夹?

标签: c# .net vb.net


【解决方案1】:

查看您的项目设置为构建目标 x86 或 x64 然后使用相同的 Microsoft.mshtml.dll 构建版本添加参考

如何知道你的项目集构建目标 右键单击项目->选择属性->选择选项卡构建->查看平台目标

【讨论】:

    【解决方案2】:

    Spire.pdf 组件在从 html 转换为 pdf 时依赖于 Microsoft Internet Explorer。因此,必须在客户端的计算机上安装 IE。以下是 Spire.pdf 支持论坛的链接。您可以在那里找到更多信息。
    https://www.e-iceblue.com/forum/could-not-load-file-or-assembly-microsoft-mshtml-version-7-t5207.html

    【讨论】:

    • IE 安装在我亲自检查过的客户端 PC 上
    • 我不知道是什么原因导致了这个问题,但根据支持论坛的聊天,它可能与 IE 有关。他们还建议使用他们的“打印到文件”插件。请检查您是否可以使用它。他们似乎解决了这个问题。请参阅论坛页面的末尾。
    • 新插件链接:e-iceblue.com/Tutorials/Spire.PDF/Spire.PDF-Program-Guide/…>
    • 谢谢法哈德我已经检查了那篇文章但对我没有用我将插件放在同一个文件夹中但它抛出错误 System.InvalidOperationException: 找不到转换提供程序。请确保: 1. Spire.Pdf.dll 同文件夹下的“plugins”文件夹 2. 存在“plugins\HTMLConverter.dll”和其他“plugins*.dll”
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-15
    • 2020-05-09
    相关资源
    最近更新 更多