Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not load file or assembly 'itextsharp' or one of its dependencies

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>
like image 714
dotnet-practitioner Avatar asked Oct 25 '25 12:10

dotnet-practitioner


2 Answers

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.

  • Intro video (2 mins video showing you what to do to make it work.)
  • Sample projects of Github
like image 51
Al Nyveldt Avatar answered Oct 28 '25 02:10

Al Nyveldt


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.

like image 32
Deep Blue Avatar answered Oct 28 '25 03:10

Deep Blue