5

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?

7
  • Try adding references to those missing assemblies into your project. They might not be added implicitly. You might need to add them explicitly. Commented Apr 18, 2015 at 12:55
  • 1
    which flavor of .net are you using? .net core or .net framework? Commented Apr 18, 2015 at 13:06
  • 1
    Sorry for not explaining clearly, I am using .Net Core. I'm developing mainly on my MacBook so that's why I want to use ASP.NET 5. I get the same error in both Visual Studio, and with kpm build on my Mac. The project will probably not be finished until ASP.NET is released anyway. Maybe it's better to start with the old version and migrate the project over to ASP.NET 5 when it is finished? Commented Apr 18, 2015 at 13:34
  • 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. Commented Apr 18, 2015 at 13:45
  • 1
    I see. Thanks for the help anyway :) I didn't even understand that there were different versions of .NET when I started this post. Now I see why it's not working. Commented Apr 18, 2015 at 17:33

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

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"
      }
    }
  },

2 Comments

This will allow iTextSharp to install, but it will not allow you to interact with it in any of your .net core namespaces
I'm using VS2017 and I'm trying to reference textsharp from one .Net Core 1.1 class library project. I find your answer interesting, but currently I don't have a Package.json in my class library, how can I add one? If I just copy paste your content in the package.json I've the feeling this will not be enough. I think now VS2017 is putting everything in the csproj, but I'm unable to find how to specify to reference the .Net 4.6 + iTextSharp

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.