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


see link converting html pdf got version error in webconfig let genius find , solve qustion.

my model

 public class customer   {     public int customerid { get; set; }     public string firstname { get; set; }     public string lastname { get; set; }   } 

my controller normal code

 public actionresult index()     {         list<customer> customers = new list<customer>();          (int = 1; <= 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 pdf convert controller

public actionresult pdf()     {         list<customer> customers = new list<customer>();          (int = 1; <= 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 couple of problems.

first, have version binding redirect in place:

<bindingredirect oldversion="0.0.0.0-5.5.5.0" newversion="5.5.5.0" /> 

this giant blanket statement assumes no api changes have taken place between version 0.0.0.0 , 5.5.5.0. however, some/many/most/all libraries out there increment major , minor version numbers when there api change.

second, related first, between itextsharp 4.1.6 (the last released itextsharp in 4.x series, ported java 2.x series) , 5 there in fact api changes. in specific case, class itextsharp.text.html.htmlparser removed why getting exception.

there's couple of ways fix this.

option #1 - way

  1. get rid of razorpdf. hasn't been updated in 2 , half years, requires obsolete version of itextsharp , uses obsolete html parser.

  2. switch using itextsharp's newer html parsing xmlworker. see (long winded) answer how use it.

option #2 - bad way

  1. read fourth box on official itext website's sales faq page title "why shouldn't use itext 2.x (or itextsharp 4.x)?"

  2. download itextsharp 4.1.6 source code. you'll need on own. don't bother asking version not supported community or makers of software.

  3. have legal counsel inspect source code, line line, ensure complies jurisdiction's laws international treaties regarding copyrights. seriously.

  4. if legal counsel approves source code, compile it, remove binding redirect , drop dll project.

  5. accept fact version 4.1.6's parser very, limited , has couple of known issues throw exceptions consider valid html. accept if ask support these problems told 2 things, upgrade recent version , switch htmlworker xmlworker.

option #3 - ugly way (for bruno)

  1. download official itextsharp source.

  2. re-implement itextsharp.text.html.htmlparser , other missing classes, methods , properties using either 4.1.6 logic or own.

  3. compile , link


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -