Unable to use iTextSharp with ASP.NET 5 Core

风格不统一 提交于 2019-12-22 05:58:39

问题


I'm trying to use iTextSharp with ASP.NET 5 Core. However I get these errors when I'm trying to build the ASP.NET application with iTextSharp 5.5.5

Code:

using Microsoft.AspNet.Mvc;
using System.IO;
using System;
using iTextSharp;
using iTextSharp.text;
using iTextSharp.text.pdf;

// For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860

namespace MyNamespace
{
    public class GenerateFileController : Controller
    {
        // GET: /<controller>/
        public string Index()
        {
            PdfReader reader = new PdfReader("template.pdf");
            return "SomeText";
        }
    }
}

Errors:

Error CS0012 The type 'Uri' is defined in an assembly that is not referenced. You must add a reference to assembly 'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. MyProject.ASP.NET 5.0 MyProject/Controllers\GenerateFileController.cs 17

Error CS0012 The type 'Stream' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. MyProject.ASP.NET Core 5.0 MyProject/Controllers\GenerateFileController.cs 17

When I'm trying to do the same thing with ASP.NET 4.6 templates, it works fine. The problem is that I want to use ASP.NET 5 Core for this project. Any Solution?


回答1:


Most existing packages will not support asp.net Core 5 yet; because of the significant differences, they need to be manually updated. If you're wanting to use iTextSharp, you'll either need to stick to asp.net 5 (not Core) or wait for the creators of iTextSharp to release a Core version.




回答2:


For now rather than wait for a package update a work around for this is simply including the Asp.net 4.6 framework and list itextsharp as one of the depenencies.

Packages.json

"frameworks": {
    "netcoreapp1.0": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "version": "1.0.1",
          "type": "platform"
        }
      },
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    },
    "net461": {
      "dependencies": {
         "iTextSharp": "5.5.10"
      }
    }
  },


来源:https://stackoverflow.com/questions/29717625/unable-to-use-itextsharp-with-asp-net-5-core

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