fpanaccia / Wkhtmltopdf.NetCore-deprecated

Rotativa + Net Core
The Unlicense
220 stars 94 forks source link

Could not load type 'Wkhtmltopdf.NetCore.HtmlAsPdf' #34

Closed jlfjunior closed 4 years ago

jlfjunior commented 4 years ago

After install Wkhtmltopdf.NetCore version 3.0.2 to using an project that depend of Wkhtmltopdf.NetCore version 1.1.3 the error happens below.

An exception of type 'System.TypeLoadException' occurred in BankSlip.Api.dll but was not handled in user code: 'Could not load type 'Wkhtmltopdf.NetCore.HtmlAsPdf' from assembly 'Wkhtmltopdf.NetCore, Version=3.0.1.0, Culture=neutral, PublicKeyToken=null'

fpanaccia commented 4 years ago

Hi! @jlfjunior yeah, that class do not exist anymore.

Since version 2.0 now works like a service, so you have to inject it, you could take a look at the example project https://github.com/fpanaccia/Wkhtmltopdf.NetCore.Example

TL;DR

In the startup.cs you have to remove this -> Wkhtmltopdf.NetCore.RotativaConfiguration.Setup(); And add this -> services.AddWkhtmltopdf();

Then in the controller/service that you are using the HtmlAsPdf, you have to inject this interface IGeneratePdf like this readonly IGeneratePdf _generatePdf; public TestViewsController(IGeneratePdf generatePdf) { _generatePdf = generatePdf; }

Then where the HtmlAsPdf is used, you could replace it like this old version -> var builder = new HtmlAsPdf(); var pdf = builder.GetPDF(html); new version -> var pdf = _generatePdf.GetPDF(html);

Let me know if this helps you

jlfjunior commented 4 years ago

after the changes other error is presented:

An exception of type 'System.Exception' occurred in Wkhtmltopdf.NetCore.dll but was not handled in user code at Wkhtmltopdf.NetCore.WkhtmlDriver.Convert(String wkhtmlPath, String switches, String html) at Wkhtmltopdf.NetCore.GeneratePdf.GetPDF(String html)

        var html = BankSlip.MontaHtmlEmbedded();
        var pdf = _generatePdf.GetPDF(html);

        return pdf;
fpanaccia commented 4 years ago

could you post the full stack trace?

jlfjunior commented 4 years ago

Yes, follows informations below.

Exception has occurred: CLR/System.Exception An exception of type 'System.Exception' occurred in Wkhtmltopdf.NetCore.dll but was not handled in user code at Wkhtmltopdf.NetCore.WkhtmlDriver.Convert(String wkhtmlPath, String switches, String html) at Wkhtmltopdf.NetCore.GeneratePdf.GetPDF(String html) at BankSlip.Api.Models.Services.BankSlipService.GeneratePdf(IEnumerable`1 bankSlips, Boolean paymentBooklet) in C:\Users\junior\Documents\PagCerto\BankSlip\src\BankSlip.Api\Models\Services\BankSlipService.cs:line 28 at BankSlip.Api.Controllers.PrintController.GeneratePdf(BankSlipPdfModel model) in C:\Users\junior\Documents\PagCerto\BankSlip\src\BankSlip.Api\Controllers\PrintController.cs:line 26 at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters) at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync() at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()

fpanaccia commented 4 years ago

As an clean example, i just did this example project, it does not have the binaries of rotativa because of size restriction in the comments. WebApplication1.zip

fpanaccia commented 4 years ago

hmm it seems like a problem with the HTML....how were you using it before? the HTML, is a razor view or a "hardcoded" HTML?

jlfjunior commented 4 years ago

I'm using "hardcode" html. when executing the project WebApplication, the same error happens:

Exception has occurred: CLR/System.Exception An exception of type 'System.Exception' occurred in Wkhtmltopdf.NetCore.dll but was not handled in user code at Wkhtmltopdf.NetCore.WkhtmlDriver.Convert(String wkhtmlPath, String switches, String html) at Wkhtmltopdf.NetCore.GeneratePdf.GetPDF(String html) at WebApplication1.Controllers.TestController.Get() in C:\Users\junior\Downloads\WebApplication1\Controllers\TestController.cs:line 37 at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters) at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync() at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()

fpanaccia commented 4 years ago

Have you added the binaries of rotativa, like this? image

What version of net core are you running?

fpanaccia commented 4 years ago

Using the same project + the binaries i am running it fine

image

jlfjunior commented 4 years ago

Yes, I'm using dotnet core 3.1.

image

image

fpanaccia commented 4 years ago

are you using omnisharp? i will try it in vscode

jlfjunior commented 4 years ago

I'm using vscode with omnisharp, I thank you.

fpanaccia commented 4 years ago

image

This is my launch.json

{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": ".NET Core Launch (web)", "type": "coreclr", "request": "launch", "preLaunchTask": "build", "program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/WebApplication1.dll", "args": [], "cwd": "${workspaceFolder}", "stopAtEntry": false, "serverReadyAction": { "action": "openExternally", "pattern": "\bNow listening on:\s+(https?://\S+)" }, "env": { "ASPNETCORE_ENVIRONMENT": "Development" }, "sourceFileMap": { "/Views": "${workspaceFolder}/Views" } }, { "name": ".NET Core Attach", "type": "coreclr", "request": "attach", "processId": "${command:pickProcess}" } ] }

fpanaccia commented 4 years ago

i will download the version 3.1.7 of net core and try again

jlfjunior commented 4 years ago

When using your launch.json the same problem occur.

PS C:\Users\junior\Downloads\WebApplication1> dotnet --info
.NET Core SDK (reflecting any global.json): Version: 3.1.401 Commit: 39d17847db

Runtime Environment: OS Name: Windows OS Version: 10.0.19041 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\3.1.401\

Host (useful for support): Version: 3.1.7 Commit: fcfdef8d6b

.NET Core SDKs installed: 2.2.207 [C:\Program Files\dotnet\sdk] 3.1.401 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.All 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs: https://aka.ms/dotnet-download

fpanaccia commented 4 years ago

my dotnet info, looks like this now

.NET Core SDK (reflecting any global.json): Version: 3.1.401 Commit: 39d17847db

Runtime Environment: OS Name: Windows OS Version: 10.0.19041 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\3.1.401\

Host (useful for support): Version: 3.1.7 Commit: fcfdef8d6b

.NET Core SDKs installed: 3.1.100 [C:\Program Files\dotnet\sdk] 3.1.302 [C:\Program Files\dotnet\sdk] 3.1.400-preview-015151 [C:\Program Files\dotnet\sdk] 3.1.401 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs: https://aka.ms/dotnet-download

But still is working fine

image

maybe is the SDK 2.2.207....im gonna try and install it

fpanaccia commented 4 years ago

Even with the SDK 2.2.207 is working, i even tried running it from console...i will try to remove the others SDKs

image

fpanaccia commented 4 years ago

I deleted all SDKs and runtimes, and still i am unable to reproduce it

image

Also, this is the version of the c# extension of vscode image

if you run with "dotnet run" you have the same problem?

jlfjunior commented 4 years ago

After installing the Visual Studio Community 2019, the problem resolved. Is there any relationship?

image

fpanaccia commented 4 years ago

When you install visual studio it install a dotnet sdk (if you choose the .net core option).

Maybe there was something wrong with your sdk, you can see that now you are running the 3.1.8 version, maybe there was an issue with your installation.