未能加载类型'iTextSharp.text.html.HtmlParser“从程序集”iTextSharp的,版本= 5.5.5.0,文化=中性公钥= 8354ae6d2174ddca“ [英] Could not load type 'iTextSharp.text.html.HtmlParser' from assembly 'itextsharp, Version=5.5.5.0, Culture=neutral, PublicKeyToken=8354ae6d2174ddca'

查看:2056
本文介绍了未能加载类型'iTextSharp.text.html.HtmlParser“从程序集”iTextSharp的,版本= 5.5.5.0,文化=中性公钥= 8354ae6d2174ddca“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看到这个链接转换成HTML到PDF我得到这个版本错误webconfig让一些天才发现并解决qustion。

我的模型

 公共类客户
  {
    公众诠释客户ID {搞定;组; }
    公共字符串名字{获得;组; }
    公共字符串名字{获得;组; }
  }

我的控制器,这是正常的code

 公众的ActionResult指数()
    {
        清单<客户>客户=新的List<客户>();        的for(int i = 1; I< = 10;我++)
        {
            客户客户=新客户
            {
                客户ID = I,
                名字=的String.Format(名字{0},i.ToString()),
                姓氏=的String.Format(姓氏{0},i.ToString())
            };
            customers.Add(客户);
        }
        返回查看(客户);
    }

这是将PDF转换器

 公众的ActionResult PDF()
    {
        清单<客户>客户=新的List<客户>();        的for(int i = 1; I< = 10;我++)
        {
            客户客户=新客户
            {
                客户ID = I,
                名字=的String.Format(名字{0},i.ToString()),
                姓氏=的String.Format(姓氏{0},i.ToString())
            };
            customers.Add(客户);
        }        返回新RazorPDF.PdfResult(客户,PDF);
    }

我的webconfig

 < dependentAssembly>
    < assemblyIdentity名称=iTextSharp的公钥=8354ae6d2174ddca文化=中性/>
    < bindingRedirect oldVersion =0.0.0.0-5.5.5.0NEWVERSION =5.5.5.0/>
  < / dependentAssembly>


解决方案

您已经有了一对夫妇的问题。

首先,你有一个版本绑定重定向到位:

 < bindingRedirect oldVersion =0.0.0.0-5.5.5.0NEWVERSION =5.5.5.0/>

这是不承担任何API的变化采取了版本之间发生一个巨大的毯子声明 0.0.0.0 5.5.5.0 。然而,一些/许多/大多数/所有的库外面的增加主要和次要版本号时,有一个API的变化。

其次,但与第一,iTextSharp的4.1.6之间(最后释放iTextSharp的在4.x的系列,从Java 2.x的系列移植)和5有实际上一些API更改。在你非常特殊的情况下,类 iTextSharp.text.html.HtmlParser 辗转这就是为什么越来越那个例外。

有一对夫妇的方式来解决这个问题。

选项#1 - 好办法


  1. 摆脱RazorPDF的。它没有在两年半了更新,它需要iTextSharp的一个过时版本,并使用一个过时的HTML解析器。


  2. 切换到使用iTextSharp的较新的HTML解析 XmlWorker 请参阅如何使用它这(长篇大论)的答案。


选项#2 - 糟糕的方法


  1. 阅读官方 iText的网站的销售FAQ页面标题第四盒子为什么不应该使用iText的2.X(或4.x的iTextSharp的)?


  2. 下载4.1.6 iTextSharp的的源$ C ​​$ C 的。你需要寻找这个你自己。不要打扰问在哪里得到它,因为这版本不是由社区或软件甚至支持厂商。


  3. 有您的法律顾问一行视察源$ C ​​$ C,线,以确保其所在辖区的法律以及有关版权的任何国际条约的规定。认真。


  4. 如果您的法律顾问批准源$ C ​​$ C,编译它,删除绑定重定向和DLL拖放到你的项目。


  5. 接受一个事实,即版本4.1.6的解析器是非常非常有限的,有几个已知的问题,将抛出什么你会考虑完全有效的HTML例外。也接受,如果你询问你会被告知两件事,升级到最新版本,并从 HTMLWorker 切换到 XmlWorker 。


选项#3 - 的丑陋的方式(布鲁诺)


  1. 下载href=\"http://sourceforge.net/projects/itextsharp/\" rel=\"nofollow\">官方iTextSharp的源的


  2. 无论使用4.1.6逻辑或自己重新实现 iTextSharp.text.html.HtmlParser 和所有其他缺少类,方法和属性。


  3. 编译和链接


see this link converting html to pdf I got this version error in webconfig let some genius find and solve the qustion.

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

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

 <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. However, some/many/most/all libraries out there increment their major and minor version numbers when there is an API change.

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. In your very specific case, the class iTextSharp.text.html.HtmlParser was removed which is why are getting that exception.

There's a couple of ways to fix this.

Option #1 - The Good Way

  1. Get rid of 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.

  2. Switch to using iTextSharp's newer HTML parsing XmlWorker. See this (long winded) answer for how to use it.

Option #2 - The Bad Way

  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)?"

  2. Download the iTextSharp 4.1.6 source code. 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.

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

Option #3 - The Ugly Way (for Bruno)

  1. Download the official iTextSharp source.

  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.

  3. Compile and link

这篇关于未能加载类型'iTextSharp.text.html.HtmlParser“从程序集”iTextSharp的,版本= 5.5.5.0,文化=中性公钥= 8354ae6d2174ddca“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆