MVC Rotativa PDF IIS Server Error

Once you try to work to generate the PDF using Rotativa, you may face the error which I faced. It ruined my whole day. I hope somehow you people save time.
 
Error which you may see :
  1. Unhandled Execution Error  
  2. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.  
  3.   
  4. Exception Details: System.Exception:  
  5.   
  6. Source Error:  
  7.   
  8. An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  
  9.   
  10. Stack Trace:  
  11.   
  12.   
  13. [Exception]  
  14.    Rotativa.WkhtmltopdfDriver.Convert(String wkhtmltopdfPath, String switches, String html) +1364  
  15.    Rotativa.WkhtmltopdfDriver.ConvertHtml(String wkhtmltopdfPath, String switches, String html) +70  
  16.    Rotativa.ViewAsPdf.CallTheDriver(ControllerContext context) +1986  
  17.    Rotativa.AsPdfResultBase.BuildPdf(ControllerContext context) +380  
  18.    Rotativa.AsPdfResultBase.ExecuteResult(ControllerContext context) +69  
  19.    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +109  
  20.    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +890  
  21.    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +97  
  22.    System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +241  
  23.    System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +29  
  24.    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +111  
  25.    System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53  
  26.    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +19  
  27.    System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +51  
  28.    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +111  
  29.    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606  
  30.    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288  
  31.   
  32.   
  33. Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34248   
While generating the pdf you may see this error. There are some basic steps you have to follow to remove this error.

Step 1:
 
Try to install  "Visual C++ Redistributable Packages" you may found those packages in microsoft site, very easily. 

Note : If your production server wont allow to install this package then find (MSVCP120.dll)
 
Step 2:  Once you have used the Rotativa pdf form nuget packaged manager you must have got some executable inside it. as shown in the below image
 
 
Step 3: If you try to use this application to execute itself and test the what error you are facing while creating the pdf, try this way, the actual error you will get it. 
  1. c:\inetpub\wwwroot\DummyProject\Rotativa\wkhtmltopdf.exe  d:\Pdf\Dummy.html d:\Pdf\Dummy.pdf  
After executing this line of code either you will get fresh pdf file or MSVCP120.dll missing error.
 
Step 4: This is the final stage you have to only place those dll inside the Rotativa folder which you are hosted in the IIS . If you are enable to execute the  Visual C++ Redistributable Packages in production server, no need to worry, Only just placed "MSVCP120.dll" inside the Rotative folder. This will work fine.
 
Summary
 
This article explains a common bug, when we try to upload our website in production server and we have used the Rotativa dll, this error might may occur. On this issue this method works.  

Up Next
    Ebook Download
    View all
    Learn
    View all