简体   繁体   English

无法从程序集'itextsharp,Version = 5.5.5.0,Culture = neutral,PublicKeyToken = 8354ae6d2174ddca'加载类型'iTextSharp.text.html.HtmlParser'

[英]Could not load type 'iTextSharp.text.html.HtmlParser' from assembly 'itextsharp, Version=5.5.5.0, Culture=neutral, PublicKeyToken=8354ae6d2174ddca'

see this link converting html to pdf I got this version error in webconfig let some genius find and solve the qustion. 看到此链接将html转换为pdf,我在webconfig中遇到此版本错误,让一些天才找到并解决了这个问题。

My Model 我的模特

 public class Customer
  {
    public int CustomerID { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
  }

My Controller this is normal code 我的控制器,这是正常代码

 public ActionResult Index()
    {
        List<Customer> customers = new List<Customer>();

        for (int i = 1; i <= 10; i++)
        {
            Customer customer = new Customer
            {
                CustomerID = i,
                FirstName = string.Format("FirstName{0}", i.ToString()),
                LastName = string.Format("LastName{0}", i.ToString())
            };
            customers.Add(customer);
        }
        return View(customers);
    }

this is for pdf convert controller 这是PDF转换控制器

public ActionResult PDF()
    {
        List<Customer> customers = new List<Customer>();

        for (int i = 1; i <= 10; i++)
        {
            Customer customer = new Customer
            {
                CustomerID = i,
                FirstName = string.Format("FirstName{0}", i.ToString()),
                LastName = string.Format("LastName{0}", i.ToString())
            };
            customers.Add(customer);
        }

        return new RazorPDF.PdfResult(customers, "PDF");
    }

My webconfig 我的webconfig

 <dependentAssembly>
    <assemblyIdentity name="itextsharp" publicKeyToken="8354ae6d2174ddca" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-5.5.5.0" newVersion="5.5.5.0" />
  </dependentAssembly>

You've got a couple of problems. 你有几个问题。

First, you have a version binding redirect in place: 首先,您有一个版本绑定重定向:

<bindingRedirect oldVersion="0.0.0.0-5.5.5.0" newVersion="5.5.5.0" />

This is a giant blanket statement that assumes no API changes have taken place between version 0.0.0.0 and 5.5.5.0 . 这是一个巨大的总括性声明,它假定在0.0.0.0版和5.5.5.0版之间未进行API更改。 However, some/many/most/all libraries out there increment their major and minor version numbers when there is an API change. 但是,当API发生更改时,某些/很多/大多数/所有库都会增加其主要版本和次要版本号。

Second, but related to the first, between iTextSharp 4.1.6 (the last released iTextSharp in the 4.x series, ported from the Java 2.x series) and 5 there was in fact some API changes. 其次,但与第一个有关,在iTextSharp 4.1.6(从Java 2.x系列移植到的4.x系列中的最后一个iTextSharp)和5之间,实际上有一些API更改。 In your very specific case, the class iTextSharp.text.html.HtmlParser was removed which is why are getting that exception. 在您的特定情况下,类iTextSharp.text.html.HtmlParser被删除,这就是为什么要获取该异常的原因。

There's a couple of ways to fix this. 有两种方法可以解决此问题。

Option #1 - The Good Way 选项1-好方法

  1. Get rid of RazorPDF. 摆脱RazorPDF。 It hasn't been updated in two and a half years, it requires an obsolete version of iTextSharp and uses an obsolete HTML parser. 它已经有两年半没有更新了,它需要一个过时的iTextSharp版本,并使用一个过时的HTML解析器。

  2. Switch to using iTextSharp's newer HTML parsing XmlWorker . 切换到使用iTextSharp的较新HTML解析XmlWorker See this (long winded) answer for how to use it . 有关如何使用它的信息,请参见此答案(冗长的答案)

Option #2 - The Bad Way 选项2-错误的方式

  1. Read the fourth box on the official iText website's sales FAQ page title "Why shouldn't I use iText 2.x (or iTextSharp 4.x)?" 阅读iText官方网站的销售常见问题解答页面标题上的第四个框:“为什么不使用iText 2.x(或iTextSharp 4.x)?”

  2. Download the iTextSharp 4.1.6 source code . 下载iTextSharp 4.1.6 源代码 You'll need to look for this on your own. 您需要自己寻找。 Don't bother asking where to get it as this version is not supported by the community or even the makers of the software. 不要担心问到哪里可以得到它,因为社区甚至软件制造商都不支持该版本。

  3. Have your legal counsel inspect the source code, line by line, to ensure that it complies with your jurisdiction's laws as well as any international treaties regarding copyrights. 让您的法律顾问逐行检查源代码,以确保其符合您所在管辖区的法律以及任何有关版权的国际条约。 Seriously. 说真的

  4. If your legal counsel approves the source code, compile it, remove the binding redirect and drop the DLL into your project. 如果您的法律顾问批准了源代码,请对其进行编译,然后删除绑定重定向并将DLL放入您的项目中。

  5. Accept the fact that version 4.1.6's parser is very, very limited and has a couple of known issues that will throw exceptions for what you would consider perfectly valid HTML. 接受以下事实:版本4.1.6的解析器非常非常有限,并且存在几个已知问题,这些问题会引发您认为完全有效的HTML的异常。 Also accept that if you ask for any support for these problems you will be told two things, to upgrade to the most recent version and to switch from HTMLWorker to XmlWorker . 还接受如果您要求对这些问题提供任何支持,您将被告知两件事,即升级到最新版本以及从HTMLWorker切换到XmlWorker

Option #3 - The Ugly Way (for Bruno) 选项#3-丑陋的方式 (适用于Bruno)

  1. Download the official iTextSharp source . 下载官方的iTextSharp源码

  2. Re-implement the iTextSharp.text.html.HtmlParser and all other missing classes, methods and properties using either the 4.1.6 logic or your own. 使用4.1.6逻辑或您自己的逻辑重新实现iTextSharp.text.html.HtmlParser和所有其他缺少的类,方法和属性。

  3. Compile and link 编译链接

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法加载文件或程序集&#39;itextsharp,Version = 5.5.0.0,Culture = neutral,PublicKeyToken = 8354ae6d2174ddca&#39;或其依赖项之一 - Could not load file or assembly 'itextsharp, Version=5.5.0.0, Culture=neutral, PublicKeyToken=8354ae6d2174ddca' or one of its dependencies 无法从程序集“ EPaymentInvoicing,版本= 1.0.0.0,区域性=中性,PublicKeyToken =空”中加载类型“ AgencySystem” - Could not load type 'AgencySystem' from assembly 'EPaymentInvoicing, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' 无法从程序集 'GraphQL,Version=3.0.0.0,Culture=neutral,PublicKeyToken=null' 加载类型 'GraphQL.Http.IDocumentWriter' - Could not load type 'GraphQL.Http.IDocumentWriter' from assembly 'GraphQL, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null' 无法加载文件或程序集“Noesis.Javascript, Version=0.0.0.0, Culture=neutral, PublicKeyToken=ae36d046c7f89f85”或其依赖项之一 - Could not load file or assembly 'Noesis.Javascript, Version=0.0.0.0, Culture=neutral, PublicKeyToken=ae36d046c7f89f85' or one of its dependencies 无法从程序集“System.Web,版本=4.0.0.0,文化=中性,PublicKeyToken=b03f5f7f11d50 - Could not load type 'System.Web.UI.ParseChildrenAttribute' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50 无法从程序集“ Nancy.Owin,Version = 0.23.2.0,Culture = neutral,PublicKeyToken = null”中加载类型&#39;Owin.Extensions&#39; - Could not load type 'Owin.Extensions' from assembly 'Nancy.Owin, Version=0.23.2.0, Culture=neutral, PublicKeyToken=null' {“无法从程序集“ Pipeline,版本= 1.0.0.0,文化=中性,PublicKeyToken =空”中加载类型&#39;VBR.Pipeline.Domain.ExpertGuide&#39;。” - {“Could not load type 'VBR.Pipeline.Domain.ExpertGuide' from assembly 'Pipeline, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.” Twilio Rest API引发错误:无法从程序集“ Twilio,版本= 1.0.0.0,文化=中性,PublicKeyToken =空”中加载类型“ Twilio.TwilioClient” - Twilio Rest API throws Error: Could not load type 'Twilio.TwilioClient' from assembly 'Twilio, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' 无法从程序集“WebDriver,版本=4.0.0.0,Culture=neutral,PublicKeyToken=null”加载类型“OpenQA.Selenium.Internal.IWrapsElement” - Could not load type 'OpenQA.Selenium.Internal.IWrapsElement' from assembly 'WebDriver, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null' 无法从程序集&#39;ADODB,Version = 7.0.3300.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a&#39;中加载类型&#39;ADODB._Recordset_Deprecated&#39; - Could not load type 'ADODB._Recordset_Deprecated' from assembly 'ADODB, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM