Wednesday, May 13, 2015

Solving Rotativa Unhandled Exception Error

Rotativa is a great tool used to convert your html views to PDF files in web projects, it works fine with ASP.Net webforms and MVC where razor views can be converted to readable pdf, more information about Rotativa in the link below:

Rotativa Official website

You can Also download Rotativa for ASP.Net Nuget package in this link.
Rotativa Nuget

While working on different servers I have an error with unhandled exception when using rotativa, the error was:

Exception Description:: System.Exception at Rotativa.WkhtmltopdfDriver.Convert(String wkhtmltopdfPath, String switches, String html) at Rotativa.WkhtmltopdfDriver.Convert(String wkhtmltopdfPath, String switches) at Rotativa.AsPdfResultBase.CallTheDriver(ControllerContext context) at Rotativa.AsPdfResultBase.BuildPdf(ControllerContext context) at Rotativa.AsPdfResultBase.ExecuteResult(ControllerContext context) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass1e.<>c__DisplayClass28.b__19() at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass1e.b__1b(IAsyncResult asyncResult)

After investigating with the issue, I start thinking of running the Rotativa execution program from the Command Prompt, like this:

wkhtmltopdf.exe README.txt test.pdf

So I Got an error:



This error is a missing C++ redistributable Package for Visual studio 2013 file called (MSVCP120.dll).

To solve the issue:
1. Open the C++ redistributable Package for Visual studio 2013 downloadable link below:
download Visual C++ Redistributable Packages for Visual Studio 2013

2. Click Download and choose the file (vcredist_x86.exe) even if you are running X64 bit server version.

3. Install the file.

this will add the missing dll file mentioned above, and the problem is now solved.

Happy Codding.