1

I've currently a problem with the NReco.ImageGenerator in a .NET Core 2.x console application that I can't get an image because of course, the console application is not web service at all.

My question now is: Is there a way to use a somehow web service in a console application so I can generate an image from an HTML code/file or is there any other solution to generate an image from HTML code/file in a .NET Core 2.x console application?

Edit

It works on .NET Standard but not on .NET Core.

var html = string.Format("<h1>Hello World!</h1>");
var converter = new HtmlToImageConverter // Exception happens here
        {
            Width = 250,
            Height = 70
        };
var bytes = converter.GenerateImage(html, NReco.ImageGenerator.ImageFormat.Png); 

Exception:

System.TypeLoadException: Could not load type 'System.Web.HttpContext' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
at NReco.ImageGenerator.HtmlToImageConverter..ctor()
at SESL.Modules.SESL.User.UserImage() in E:\Source\SESL-Discord\SESL\Modules\SESL\User.cs:line 36
5
  • I am a bit confused, but the console application can call a web service or a web request and return either a stream or byte[] of data for you to handle however you want. Could you provide more information? Like some code? Commented Nov 1, 2018 at 20:46
  • I'm guessing the OP might not realize that a console application can call a web service or a web request and read the response stream. Hence my reply below. Personally, I'd just use System.Net.Http.HttpClient. Commented Nov 1, 2018 at 21:30
  • @Greg I added a code block and the exception. @paulsm4 I would do the same but the problem is, it's not depended on System.Net.Http.HttpClient but System.Web Commented Nov 2, 2018 at 1:48
  • Just to clarify, you want to execute the NReco.ImageGenerator from within the console application itself, ie. the generated is hosted by the console application. You don't want to have a web service host the generator and have the console application connect to it via HTTP Client. Commented Nov 2, 2018 at 2:07
  • @Adrian Yes, it should be in the same console application. Commented Nov 2, 2018 at 2:15

1 Answer 1

1

I found out, that the NReco.ImageGenerator does not support .NET Core and for the .NET Core I need to pay the LT version. But I discovered another NuGet Package which does somehow the same but I need to draw the image by myself. Therefore the alternative is Magick.NET

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

Comments

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.