3

Trying to follow this tutorial for RazorPDF, and I don't know why am I getting the following error message: Very frustrated and tired.

Error Message:

Could not load file or assembly 'itextsharp' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

itextsharp:

RunTimeVersion: v1.1.4322 Version: 4.1.2.0

RazorPDF:

Run Time version: 4.0.30319

Inside the controller:

   public ActionResult Index()
    {
        var studentMarks = new List<MarksCard>()
        {
           new MarksCard()
            {
                RollNo = 101, Subject = "C#",
                FullMarks = 100, Obtained = 90},new MarksCard() {RollNo = 101, Subject = "asp.net", FullMarks = 100, Obtained = 80},new MarksCard() {RollNo =               101, Subject = "MVC", FullMarks = 100,
                Obtained = 100},new MarksCard() {RollNo = 101, Subject = "SQL Server", FullMarks = 100, Obtained = 75},
        };
       //// return new RazorPDF.PdfResult(studentMarks, "Index");
        return View(studentMarks);

    }

Inside View

@model IEnumerable<TimberBeamCalculator.Models.MarksCard>

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table>
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.RollNo)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Subject)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.FullMarks)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Obtained)
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.RollNo)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Subject)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.FullMarks)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Obtained)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
            @Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
            @Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
        </td>
    </tr>
}

</table>
dotnet-practitioner
  • 13,968
  • 36
  • 127
  • 200
  • Did you check your both versions itextsharp.dll and razor that was support by your current .net version ? – cat916 Jan 09 '14 at 08:09
  • 1
    This may be of interest http://stackoverflow.com/questions/16517171/convert-html-to-pdf-in-mvc-with-itextsharp-in-mvc-razor/20198939#20198939 – hutchonoid Jan 09 '14 at 10:00

6 Answers6

2

Check to be sure that you actually have iTextSharp going into the correct place. My guess is you are missing something.

I'd strongly suggest you start by following the initial project samples and trying to get them to work first.

Al Nyveldt
  • 64
  • 1
  • 2
  • Hi Al, Thanks for responding. I was able to get your sample projects from Github to work successfully on my machine. Your project is targetting .net 4.0 and my project is targetting .net 4.5 .. I don't know if that makes a difference. – dotnet-practitioner Jan 10 '14 at 04:37
  • Al, Thanks for your demo.. I restarted the code base from the point where I did not have those dlls, registered DLLs from scratch... and it worked. – dotnet-practitioner Jan 10 '14 at 04:57
  • Not sure what the problem was, I updated iTextSharp from Version 5.5.8 to 5.5.9 through NuGet and received the error. I removed it from my references list, then re-added it the dll and it worked. – Artorias2718 Jun 26 '16 at 15:15
2

This problem occurs only if you press F5 in Visual Studio to debug. If you are not debugging then always press Ctrl+F5. The problem is mainly due to some wrong configuration setting in Project File. To fix it:

  1. remove the dll from Add Reference.

  2. get a fresh copy of dll.

  3. Add the Reference of this dll.

This should fix it.

shA.t
  • 16,580
  • 5
  • 54
  • 111
Deep Blue
  • 21
  • 2
  • Not necessairly, I was not debugging when it happened to me. I normally test my site using CTRL + F5 because I don't like to stop running the site to update code and test changes. I only run it in debug if I need to run through breakpoints. – Artorias2718 Jun 26 '16 at 15:18
0

I have issue with itextsharp and itextsharp.xmlworker dlls so I have removed those both dlls from references and downloaded new dlls directly from nuget packages, which resolved my issue.

May be this method can be useful to resolved the issue to other people.

Dilip Langhanoja
  • 4,455
  • 4
  • 28
  • 37
0

I got same error while web developing in Visual Studio. The solution was to install itextSharp from Nuget Package Manager

Sahin
  • 1,032
  • 14
  • 23
0

Add referance path to .csproj you use itextsharp or referanced dll

<Reference Include="iTextSharp, Version=4.1.6.0, Culture=neutral, PublicKeyToken=8354ae6d2174ddca">
  <HintPath>..packages\iTextSharp-LGPL.4.1.6\lib\iTextSharp.dll</HintPath>
</Reference>
Jesse
  • 168
  • 1
  • 7
-1

And then compile it against the latest LGPL source code of iTextSharp. This way you can change the in use target framework version as well.

P.S. RazorPdf uses HTMLWorker of iTextSharp. It's deprecated and won't be supported anymore. It has a very limited HTML to PDF capabilities. they have replaced it with XMLWorker lately: http://sourceforge.net/projects/itextsharp/files/xmlworker/

VahidN
  • 18,457
  • 8
  • 73
  • 117