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.

53 comments:

  1. Hi Jalal... Thank you very much for your post.

    But I can't install this file on server. Is there a way to do this work just adding this dll as reference to my project?

    Thank you

    ReplyDelete
    Replies
    1. Hello Thiago, thanx for asking.
      Really i didn't tried to use only the dll file as reference to the project, but i'm not sure it will work, because at the end the dll will call the wkhtmltopdf.exe to execute the conversion.
      So I think you have to install the Rotativa Nuget.

      Delete
    2. u need to buy vps server , bec on that u can connect to server through remote desktop connection , and it will be a whole computer as u will have in local .

      Delete
    3. Jalal Hijazi Blog: Solving Rotativa Unhandled Exception Error >>>>> Download Now

      >>>>> Download Full

      Jalal Hijazi Blog: Solving Rotativa Unhandled Exception Error >>>>> Download LINK

      >>>>> Download Now

      Jalal Hijazi Blog: Solving Rotativa Unhandled Exception Error >>>>> Download Full

      >>>>> Download LINK Gd

      Delete
  2. Hi Jilal,

    I am also facing the same issue..Is it sufficient to install that exe file on my sever ..???

    Thanks Advance.:-)

    ReplyDelete
    Replies
    1. Hi Hari krishna Allu, did you fix your problem just installing the .exe file on your server?

      Delete
    2. Hello Hari, Elvis
      I think you need to copy the Nuget folder which contains the Rotativa dll and exe files to your server and run the wkhtmltopdf.exe, it should work

      Delete
    3. Hello, thanks, I just fix the problem copying the following file to the Rotativa folder in the server.

      https://drive.google.com/file/d/0BzI_u_O3vUM1aEppb3ZVZXNsc28/view

      Delete
    4. Thank you Elvis Rocha... this fix the problem.

      Delete
    5. Thanx Buddy Elvis Rocha. I have this file in my rotativa folder but still not working then I downlead your link file and replace there and its worked for Me

      Delete
  3. Great post - thank you! I had exactly this issue.
    Following your comments, I just copied msvcp120.dll and msvcr120.dll to the folder containing wkhtmltopdf.exe and all worked fine.
    Thanks for your help,
    Clive

    ReplyDelete
    Replies
    1. I'm glad that it helped you in some way.
      Happy Coding :)

      Delete
    2. Thanks!!!

      This is really working: "I just copied msvcp120.dll and msvcr120.dll to the folder containing wkhtmltopdf.exe and all worked fine"

      Delete
  4. Thank you! - You saved my morning! :)

    ReplyDelete
  5. Thanks Very much for the fix. I appreciate it. I copied the dlls into published Rotativa folder on hosting server as @Clive N said and it fixed the problem.

    ReplyDelete
  6. Thank you very much! This saved me a lot of time!

    Best regards, Janno

    ReplyDelete
  7. Thanks @jalal. After installing C++ redistributable Package for Visual studio 2013 on server I fixed my issue

    ReplyDelete
  8. Thx!! Its work for me by replacing 'wkhtmltopdf.exe' in Rotativa Folder.

    ReplyDelete
    Replies
    1. Hi Omprakash I don't understand by what you replaced the 'wkhtmltopdf.exe'

      Delete
  9. Sincere appreciation here... I added the 2 DLL files to the Rotativa folder on my server, and everything is working as expected!

    ReplyDelete
  10. This comment has been removed by the author.

    ReplyDelete
  11. This really saved my day ... I did an update of the NuGet package and it broke down
    Thanks a million !

    ReplyDelete
  12. server is not giving permission to wkhtmltopdf.exe

    ReplyDelete
    Replies
    1. maybe you may install it using administrator privileges.

      Delete
  13. thanks guys that really helped me..I was also having the same error

    ReplyDelete
  14. thanks guys.. it really helped me.I was planning to change the solution for generating pdf.But at last it works.. !!! - Vivek

    ReplyDelete
  15. Good job! it really helped me...

    ReplyDelete
  16. Thanks a lot! You saved my day!

    ReplyDelete
  17. I am having shared hosting, Not allow to upload rotativa.exe, is any other solution.

    ReplyDelete
  18. can somebody tell me where i can find these files in the system so that i can copy them to the server. Thanks ,

    ReplyDelete
  19. Im afraid, that copying the two .dll files to my server did NOT solve my problem. I still get System.Exception error :-(
    Is there any other things i can try. I have no access to installing things on server.

    ReplyDelete
    Replies
    1. Same here, did you end up resolving this Johnny?

      Delete
  20. Install from https://wkhtmltopdf.org/downloads.html (in my case I have downloaded - MSVC 2015 win64 Installer for Windows Vista or later

    From installer path I copied wkhtmltoimage.exe, wkhtmltopdf.exe, wkhtmltox.dll to Rotativa folder and it worked.

    ReplyDelete
    Replies
    1. wowwwww i though that this article was worthless but this comment is damn osm. i downloaded the dlls for my window server from
      this https://wkhtmltopdf.org/downloads.html and paste into www/Rotativa folder and its worked on aws. woww..

      Delete
  21. Hello Jalal , i faced the same issue i tried your solution but i am using 2 diffrent domain for same site and its working for one and not working for another also the application is also not working when i click on download.

    ReplyDelete
  22. Hi,
    What a fantastic post! This is so chock full of useful information. I can’t wait to dig deep and start utilizing the resources you have given me. This information will definitely help me.

    ReplyDelete
  23. Hello Jalal.
    I have published my file locally in IIS , I am trying to generate in Hindi and English language . It works fine while I run my program but after publish all Hindi letter converts into black square. I have checked all the possible solution but didn't help.
    please help me on this .

    ReplyDelete