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

女生的网名这么多〃 提交于 2019-11-29 08:39:23
Chris Haas

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!