1

I am using RazorPDF to return PDF as a view. The problem is that when I run on my machine the code works fine, returning the PDF as I want, but when I upload the code to IIS in Windows Server 2008, the code returns "RazorPDF.PdfResult" that is the name of the class as a string. The rest of the application works fine on both environments.

This is the correct return result, on local machine: right_return

And this is the result when running on windows server:wrong_return

The code:

public ActionResult OrcamentosResultado(LogisticaModel model, string pdf)
{
    //Some code
    if (pdf == "pdf")
    {
        PdfResult retorno = new PdfResult(model, "ComprasPDF");
        return retorno;
    }
    //Some more code
}

I am using ASP.NET 4.0 and System.Web.MVC 3.0

Tales Pádua
  • 1,331
  • 1
  • 16
  • 36
  • Are you absolutely sure you published all your changed files? – mason Oct 08 '15 at 19:03
  • Could you post the entire code ? – eng.augusto Oct 08 '15 at 19:04
  • Additional info: I have found this silimar question: http://stackoverflow.com/questions/21610854/error-converting-mvc4-view-to-pdf-with-rotativa-or-razorpdf But the answer didnt work for me, since the problem only happens on the IIS server – Tales Pádua Oct 08 '15 at 19:17
  • @mason yes, and I double checked the Web.config – Tales Pádua Oct 08 '15 at 19:19
  • Which of the following do you expect to return: 1- A Pdf Stream marked as a pdf application doc to show the pdf in a web browser; 2- a json object of some kind; 3- a text stream of some kind; 4- a graphic; 5- a full html page that should be displayed. ? I am sure you are seeing the default ToString behavior and I would argue that it works in production By Coincidence and that your code needs a little help to tell IIS/MVC what to do in all cases. – Sql Surfer Oct 08 '15 at 19:27
  • @SqlSurfer, This is an old project that I didnt wrote, I am just fixing some problems. For what I can tell, the PdfResult takes a View (in this case ComprasPDF.cshtml), converts it into pdf and then return to the browser. This project was developed in VS2012, but I am using VS 2013 now. Maybe this is some VS settings? Any idea where to look at those kind of behaviors? – Tales Pádua Oct 08 '15 at 20:21

1 Answers1

0

I found the problem and it was kinda the same as the question I mentioned in a comment above Error converting MVC4 view to PDF with Rotativa or RazorPDF

The problem was a conflict between System.web.mvc dll in the server, that was version 2.0.0.0, (on C:/Windows/assembly) and the same dll in my bin folder, version 3.0.0.1

As @SqlSurfer pointed, the 2.0.0.0 mvc dll has some ToString behavior.

To fix it, I just changed the Web.config to look for the dll on the bin folder, not the server

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.1" />
  </dependentAssembly>
</assemblyBinding>

The error was not happening in my local machine because my machine does not have the System.web.mvc dll on windows/assembly folder.

Thanks to all

Community
  • 1
  • 1
Tales Pádua
  • 1,331
  • 1
  • 16
  • 36
  • It would be interesting to know if this problem would be detected by nugget under normal circumstances or if you were actively using nugget in this situation? – Sql Surfer Oct 08 '15 at 22:25
  • @SqlSurfer, How would Nuget detect this? I used Nuget on my machine, but I dont know about the server, and I dont know why the server had the mvc dll on windows assemblies – Tales Pádua Oct 09 '15 at 16:53