Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to use iTextSharp with ASP.NET 5 Core

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?

like image 960
Gronis Avatar asked Apr 18 '15 12:04

Gronis


2 Answers

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.

like image 199
Matt DeKrey Avatar answered Nov 20 '22 11:11

Matt DeKrey


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"
      }
    }
  },
like image 44
fassetar Avatar answered Nov 20 '22 12:11

fassetar