IronPdf IronSoftwareDeploymentException in Azure Wep App

771 Views Asked by At

I am getting below exception after deploying HTML to PDF functionality in Azure Web App(.net Framework 4.8).Same is working fine in local .

IronSoftware.Exceptions.IronSoftwareDeploymentException: Error while deploying IronPdf Chrome renderer: 'Unable to locate 'IronInterop' in C:\home\site\wwwroot\, C:\home\site\wwwroot\bin, C:\local\Temporary ASP.NET Files\root\26df21a6\54e3e732\assembly\dl3\9559295f\001eed5d_d423d901, C:\home\site\wwwroot, Embedded resource (IronPdf, Version=2023.1.0.11416, Culture=neutral, PublicKeyToken=94e1c31412563c75: IronPdf) to path 'C:\home\site\wwwroot\runtimes\win-x64\native', Embedded resource (IronPdf, Version=2023.1.0.11416, Culture=neutral, PublicKeyToken=94e1c31412563c75: IronPdf) to path 'C:\home\site\wwwroot\runtimes\win.10-x64\native', Embedded resource (IronPdf, Version=2023.1.0.11416, Culture=neutral, PublicKeyToken=94e1c31412563c75: IronPdf) to path 'C:\home\site\wwwroot\' nor in an embedded resource'. To learn more about making an engineering support request please visit: <a href=https://ironpdf.com/troubleshooting/engineering-request-pdf/>.
To learn how to solve this issue please read https://iron.helpscoutdocs.com/article/194-azure-functions-deployment2 
[Issue Code IRONPDF-CHROME-DEPLOYMENT-ERROR-AMZN] ---> IronSoftware.Exceptions.IronSoftwareDeploymentException: 
Unable to locate 'IronInterop' in C:\home\site\wwwroot\, C:\home\site\wwwroot\bin, C:\local\Temporary ASP.NET Files\root\26df21a6\54e3e732\assembly\dl3\9559295f\001eed5d_d423d901,
 C:\home\site\wwwroot, Embedded resource (IronPdf, Version=2023.1.0.11416, Culture=neutral, PublicKeyToken=94e1c31412563c75: IronPdf) to path 'C:\home\site\wwwroot\runtimes\win-x64\native', 
 Embedded resource (IronPdf, Version=2023.1.0.11416, Culture=neutral, PublicKeyToken=94e1c31412563c75: IronPdf) 
 to path 'C:\home\site\wwwroot\runtimes\win.10-x64\native', Embedded resource (IronPdf, Version=2023.1.0.11416, Culture=neutral, PublicKeyToken=94e1c31412563c75: IronPdf) 
 to path 'C:\home\site\wwwroot\' nor in an embedded resourceat IronSoftware.Deployment.SmartDeploymentBase.ThrowRelevantException(List`1 exceptions)at
 IronSoftware.Deployment.SmartDeploymentBase.Deploy(Boolean download)at IronSoftware.Deployment.DeploymentEngine.Deploy[T](String custom_dir, Boolean download)--- 
 End of inner exception stack trace

I have already added dependent nuget IronPdf.Native.Chrome.Windows as suggested. Below is the code :

var renderer = new ChromePdfRenderer();
 renderer.RenderingOptions.RenderDelay = Convert.ToInt32(SiteSettingsPage.Settings.PDFRenderDelay);
                renderer.RenderingOptions.MarginTop = 12;
                renderer.RenderingOptions.MarginBottom = 12;
                renderer.RenderingOptions.MarginLeft = 0;
                renderer.RenderingOptions.MarginRight = 0;
                renderer.RenderingOptions.PaperOrientation = 
                IronPdf.Rendering.PdfPaperOrientation.Portrait;
                renderer.RenderingOptions.PaperSize = IronPdf.Rendering.PdfPaperSize.A4;
 var pdf = renderer.RenderUrlAsPdf(htmlFileUrl).BinaryData;
1

There are 1 best solutions below

0
Suresh Chikkam On

As per the above requirement I have reproduced from my end I tried your code it works fine in local but where as deployed in webapp it was showing error.

Thanks @jdweng for your suggestions in the comments. Below is the code which I tried to reproduce.

        var renderer = new ChromePdfRenderer();
        var pdf = renderer.RenderHtmlAsPdf(File.ReadAllText(htmlFilePath));
        pdf.SaveAs(pdfFilePath);

        Console.WriteLine($"PDF saved to {pdfFilePath}");
        Console.WriteLine("Conversion complete!");

        var credentials = SdkContext.AzureCredentialsFactory.FromFile("azureauth.properties");
        var azure = Azure.Configure().WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic).Authenticate(credentials).WithDefaultSubscription();
        var webApp = azure.WebApps.GetById("resource-group-name", "webapp-name");

        using (var fileStream = new FileStream(pdfFilePath, FileMode.Open))
        {
            webApp.Inner.WebApps.CreateOrUpdateSiteBlobSource("wwwroot", "pdf-file-name.pdf", fileStream);
        }

        Console.WriteLine($"PDF uploaded to {webApp.DefaultHostName}/pdf-file-name.pdf");
    }
}
  • In the above code SdkContext.AzureCredentialsFactory.FromFile method to read your Azure credentials from a file called "azureauth.properties" that should be located in the same directory as your program file.

  • azure.WebApps.GetById method retrieves an instance of your web app using the resource group and web app names.

  • FileStream object to read the contents of the PDF file, and then use the webApp.Inner.WebApps.CreateOrUpdateSiteBlobSource method to create or update a blob in the web app's root directory

enter image description here

  • I have created a webapp in portal and deployed from visual studio code editor successfully.

enter image description here

  • I am able to see the converted .html to .pdf in local Aswell as in www.root directory.

enter image description here

enter image description here