简体   繁体   English

无法加载文件或程序集“itextsharp”或其依赖项之一

[英]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.尝试按照 RazorPDF 的教程进行操作,但我不知道为什么会收到以下错误消息:非常沮丧和疲倦。

Error Message:错误信息:

Could not load file or assembly 'itextsharp' or one of its dependencies.无法加载文件或程序集“itextsharp”或其依赖项之一。 The located assembly's manifest definition does not match the assembly reference.定位的程序集的清单定义与程序集引用不匹配。 (Exception from HRESULT: 0x80131040) (来自 HRESULT 的异常:0x80131040)

itextsharp: itextsharp:

RunTimeVersion: v1.1.4322 Version: 4.1.2.0运行时版本:v1.1.4322 版本:4.1.2.0

RazorPDF:剃刀PDF:

Run Time version: 4.0.30319运行时版本: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>

Check to be sure that you actually have iTextSharp going into the correct place.检查以确保您确实将 iTextSharp 放入了正确的位置。 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.我强烈建议您从遵循初始项目示例开始,并尝试让它们首先工作。

This problem occurs only if you press F5 in Visual Studio to debug.只有在 Visual Studio 中按F5进行调试时才会出现此问题。 If you are not debugging then always press Ctrl + F5 .如果您不进行调试,请始终按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 .Add Reference删除dll

  2. get a fresh copy of dll .获取dll的新副本。

  3. Add the Reference of this dll .添加此dll的引用。

This should fix it.这应该解决它。

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.我有 itextsharp 和 itextsharp.xmlworker dll 的问题,所以我从引用中删除了这两个 dll,并直接从 nuget 包下载了新的 dll,这解决了我的问题。

May be this method can be useful to resolved the issue to other people.可能这种方法对于解决其他人的问题很有用。

I got same error while web developing in Visual Studio.我在 Visual Studio 中进行 Web 开发时遇到了同样的错误。 The solution was to install itextSharp from Nuget Package Manager解决方案是从 Nuget Package Manager 安装 itextSharp

And then compile it against the latest LGPL source code of iTextSharp.然后针对 iTextSharp 的最新 LGPL 源代码编译它。 This way you can change the in use target framework version as well.通过这种方式,您也可以更改正在使用的目标框架版本。

PS RazorPdf uses HTMLWorker of iTextSharp. PS RazorPdf使用 iTextSharp 的HTMLWorker It's deprecated and won't be supported anymore.它已被弃用,不再受支持。 It has a very limited HTML to PDF capabilities.它具有非常有限的 HTML 到 PDF 功能。 they have replaced it with XMLWorker lately: http://sourceforge.net/projects/itextsharp/files/xmlworker/他们最近用XMLWorker替换了它: http : //sourceforge.net/projects/itextsharp/files/xmlworker/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法加载文件或程序集&#39;&#39;或其依赖项之一 - Could not load file or assembly '' or one of its dependencies 无法加载文件或程序集及其依赖项之一 - Could not load file or assembly and one of its dependencies 无法加载文件或程序集或其依赖项之一 - Could not load file or assembly or one of its dependencies 无法加载文件或程序集或其依赖项之一 - could not load file or assembly or one of its dependencies 无法加载文件或程序集或其依赖项之一 - Could not load file or assembly or one of its dependencies 无法加载文件或程序集&#39;itextsharp,Version = 5.5.0.0,Culture = neutral,PublicKeyToken = 8354ae6d2174ddca&#39;或其依赖项之一 - Could not load file or assembly 'itextsharp, Version=5.5.0.0, Culture=neutral, PublicKeyToken=8354ae6d2174ddca' or one of its dependencies 无法加载文件或程序集“ xxxLib”或其依赖项之一。 BadImageFormatException - Could not load file or assembly 'xxxLib' or one of its dependencies. BadImageFormatException 无法加载文件或程序集“ BookMe”或其依赖项之一 - Could not load file or assembly 'BookMe' or one of its dependencies 无法加载文件或程序集“Elasticsearch.Net”或其依赖项之一 - Could not load file or assembly 'Elasticsearch.Net' or one of its dependencies 无法加载文件或程序集“ Newtonsoft.Json”或其依赖项之一? - Could not load file or assembly 'Newtonsoft.Json' or one of its dependencies?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM