1

I am using NReco HTML to Image Generator for .NET, but when I try to execute this line:

var htmlToImageConv = new NReco.ImageGenerator.HtmlToImageConverter();

it crashes with an exception:

enter image description here

I stumbled across this post, but I am not sure if it is related somehow.

I am obviously trying to make it work on localhost first, but I suspect there are going to be problems when I deploy to Azure as well...

I tested the Nreco lib on a console application and it (kind of) works ok. What's the problem here? I haven't posted any code, because it is literally an empty Azure Function new project with these three lines added.

nmrlqa4
  • 659
  • 1
  • 9
  • 32
  • It looks like you need assembly binding redirection, try ti google for it, hope it helps – Evgeny Gorbovoy Apr 20 '18 at 12:26
  • You can't use libraries that are already used by runtime but have different versions of those. See [this github issue](https://github.com/Azure/azure-functions-host/issues/992) – Mikhail Shilkov Apr 20 '18 at 12:44
  • I maybe understand the problem, but not entirely (this "binding redirections" as what Eugene Gorbovoy says). I read the Github posts but cannot find an appropriate solution.. Why is this limitation? I don't even know what to do to fix this problem – nmrlqa4 Apr 20 '18 at 12:55
  • In your function folder, try creating a `bin` folder and placing the assembly you wish to use in that `bin` folder. The runtime will use this location as a fallback when probing for assemblies. This may not work, but will usually fix the error! – Marie Hoeger Apr 20 '18 at 17:15
  • 1
    What target framework do you use? In case of netstandard2.0 "NReco.ImageGenerator" nuget package cannot be used as it is only for classic .NET Framework; for .NET Core apps "NReco.ImageGenerator.LT" can be used, but it is not available for free users. – Vitaliy Fedorchenko Apr 21 '18 at 07:37
  • Yes, it is .Net Standard 2.0. So I need to use LT instead? – nmrlqa4 Apr 23 '18 at 11:11
  • I have tested your issue, you are using the Azure Functions V2 but referencing the package for .NET Framework instead of the .NET Core. Since other members have provided suggestions, you'd better follow the instructions to check your code by yourself, in order to have a better understanding of it. Moreover, you'd better read [.NET Standard](https://learn.microsoft.com/en-us/dotnet/standard/net-standard). – Bruce Chen Apr 24 '18 at 02:28
  • Yes, I figured out that I am using AF V2 and .NET Standard (my Function project obviously is a Core project), so I will need the .NET Core NReco package which is labeled as "LT", but unfortunately it is paid. – nmrlqa4 Apr 24 '18 at 07:29
  • For your scenario, I would recommend you create another Azure Functions v1 (.NET Framework) or Web API to provide a endpoint for generating images using the free package` NReco.ImageGenerator`. Or you could try to find other free packages. – Bruce Chen Apr 25 '18 at 03:15

1 Answers1

0

Per my local test, you may installed NReco.ImageGenerator which targets full .net framework under your Azure Functions V2 (.NET Core). You could use Azure Functions v1 (.NET Framework) and install the above package, or you could just use NReco.ImageGenerator.LT under your V2 azure function.

Moreover, after deployed to azure side, you may hit the limitation of Azure App Service sandbox environment, I am not sure, but you could deploy your simple function app to check it before your start to build your business logic.

Bruce Chen
  • 18,207
  • 2
  • 21
  • 35