Rotativa crashes on service fabric node in Azure - c#

I have a project that needs to collect several data and put it in a single pdf, to do so I used Rotativa wrapper. It works fine on my local service fabric cluster and Im able to generate the pdf using ViewAsPdf and then getting the byte array to attach it in an email. The problem comes when I deployed the project in Azure (service fabric cluster) and Im getting this error:
at Rotativa.AspNetCore.WkhtmlDriver.Convert(String wkhtmlPath, String switches, String html, String wkhtmlExe)\r\n at Rotativa.AspNetCore.WkhtmltopdfDriver.ConvertHtml(String wkhtmltopdfPath, String switches, String html)\r\n at Rotativa.AspNetCore.ViewAsPdf.<CallTheDriver>d__19.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---
Things that Ive tried:
Installed Visual C++ Redistributable Packages for Visual Studio 2013 and 2015 in x64 and x86 versions in the service fabric node (where the project is being deployed)
Moved the Rotativa folder from wwwroot to the root path of the project and set the path in RotativaConfiguration.Setup() method
Copied msvcp120.dll and msvcr120.dll to the Rotativa folder
Installed wkhtmltopdf.exe in the service fabric node
I installed Rotativa.AspNetCore 1.0.6 nuget package
I use ViewAsPdf to render the razor view and I call BuildFile method to get the byte array
If I ran the wkhtmltopdf.exe in the command line in the service fabric node I get: "The application was unable to start correctly(0xc000007b) Click ok to close the application"
The service fabric node is a Windows machine. The project is built with aspnet core 2.0
Any help will be appreciated. Thanks!

I assume is a missing dependency issue.
Based on the scenario and message you provided The application was unable to start correctly(0xc000007b) there are other related problems:
The application was unable to start correctly (0xc000007b) and Error : the application was unable to start correctly
The other issue might be lack of permissions to run or access specific dependencies.
I would suggest you try:
running as administrator first via command line.
Check firewall or network\website permissions
Use dependency walker and check the dependencies it loads\fail and verify if they are installed on the server.

As a workaround you could create a container to run this. It would save you the trouble of going into the nodes to install stuff, which limits your scale out & fail-over options.
There are some people who got it working.

Related

IronPDF Renderer.RenderHtmlAsPdf failing when deployed to IIS

We are using ironPDF to genetate PDF file from HTML string. It is a MVC web application written in C# (.net framework 4.8) , deployed to IIS
I did the following.
Added IronPdf nuget package to the project (Version: 2022.11.10347)
Use the following code to generate PDF from string
using IronPdf; (on top of the code to add ref)
PDF generation code as below;
public ActionResult ExportPDF()
{
var Renderer = new IronPdf.ChromePdfRenderer();
var pdfDoc = Renderer.RenderHtmlAsPdf(htmlstring);
return File(pdfDoc.Stream.ToArray(), "application/pdf", "TransactionStatement.pdf");
}
here htmlstring is the html that need to be rendered to PDF
This code works fine and generates PDF when I run in my local dev machine.
But when I deploy this code to our integration environment , it is failing. It is not generating any PDF.
It just hangs for couple of minutes then our website is getting timed out and application pool is getting stopped.
the failure is happening is in the following line
var pdfDoc = Renderer.RenderHtmlAsPdf(htmlstring);
Out integration environment is in IIS (Windows server 2008 R2) . and application pool identity is NetworkService.
When I looked into the event log I can see the following warnings
Application popup: IronCefSubprocess.exe - System Error : The program can't start because api-ms-win-core-com-l1-1-0.dll is missing. from your computer. Try reinstalling the program to fix this problem.
A process serving application pool '<poolname>' suffered a fatal communication error with the Windows Process Activation Service. The process id was '5940'. The data field contains the error number.
I have all required Visual C++ redistributables installed in my server as described in the ironPDF website
Any idea how to fix this issue.
For API-MS-WIN-CORE-COM-L1-1-0.DLL. You could refer to this to reinstall API-MS-WIN-CORE-COM-L1-1-0.DLL.
About application pool error. As the community member said, need configuration information is needed to locate the cause.
In my opinion, you could try turn Enable 32-bit applications to true. If still don't work, you can refer to this using debugging tools to locate the cause.

.Net Core 3.1 Permissions Issue Based on Project Type

I have a problem that I can't seem to figure out on my own.
Basically, I have two solutions on my work computer.
Both are using .Net Core 3.1 Framework, one is the default MVC new project setup (ASP.NET Core Web App (Model View Controller)) running with IIS Express, and one is a simple console application. Both are using the nuget package Microsoft.Data.SqlClient and that is it.
However, the console application errors out on the following code, when trying to Open() the connection:
InnerException = {"Unable to load DLL 'Microsoft.Data.SqlClient.SNI.dll' or one of its dependencies: Access is denied. (0x80070005 (E_ACCESSDENIED))"}
using (var connection = new SqlConnection("Verified Connection String Here"))
{
connection.Open();
new SqlCommand("SELECT 1", connection).ExecuteNonQuery();
}
The same code when running the MVC web app (Using IIS) works fine!! What could possibly be the issue? What can I troubleshoot next? I suspect it is something with the security settings that I have no control over (I'm at a government organization)
Thank you!!
McAfee was blocking access to the DLL in the case with running the console project. There was some rule that prevented execution depending on where the project folder was located. I moved it from my users folder and the C:/ drive directly and then it worked.

Is there a way to provide IIS with the location of a DLL that your MVC solution depends on?

I am building an application that scaffolds a SSIS package using EzAPI (Version 0.8.5). The code runs perfect within visual studio, no errors or bugs until I publish the MVC application (.NET 4.5) to the IIS server (Version 10.0.14298). This is when the function fails and doesn't save the package. The following error is thrown on save:
{"The system cannot find the file specified. (Exception from HRESULT:
0x80070002)":null} source: Microsoft.SqlServer.ManagedDTS
I have ensured that SSIS, Integration services have been installed on the IIS server, exact same version as my local instance MSSQL2017 so the DLL's I require are all in the same folders. I deployed to my local instance of IIS and get the same error as well.
using Microsoft.SqlServer.SSIS.EzAPI;
EzPackage _package = new EzPackage() { Name = "Package" };
_package.SaveToFile(#"C:\Package.dtsx"); // Fails here with error
The expectation would be that the package would be generated and then I would be able to view it within the C drive but it looks like it fails when it tries to build / finalize the package
Stack Trace:
" at Microsoft.SqlServer.Dts.Runtime.Package.SaveToXML(String&
packageXml, IDTSEvents events)\r\n at
Microsoft.SqlServer.SSIS.EzAPI.EzPackage.SaveToXML(IDTSEvents
events)\r\n at
Microsoft.SqlServer.SSIS.EzAPI.EzPackage.SaveToFile(String
fileName)\r\n at method(ViewModel model) in Logic.cs:line 641"
Try creating a folder in C:. For example, C:\packages. Make sure the app pool user has read/write access to the folder. Try adding IUSR or the app pool ( IIS AppPool\ApplicationPoolName ) user to the C:\packages folder with read write permissions.

.NET executables do not work after overwritten with new versions

I faced very strange behaviour - after I overwrite .NET exectables with new versions from network drive it cannot start.
When try to start from Windows Explorer it shows me following error:
[Window Title]
C:\Programs\zzz\clients.net\zzzNet.exe
[Content]
C:\Programs\zzz\clients.net\zzzNet.exe
The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail.
I tried to execute following commands:
SxsTrace Trace -logfile:SxsTrace.etl
SxStrace Parse -logfile:SxSTrace.etl -outfile:SxSTrace.txt
And got following result:
=================
Begin Activation Context Generation.
Input Parameter:
Flags = 0
ProcessorArchitecture = AMD64
CultureFallBacks = en-US;en;ru-RU;ru
ManifestPath = C:\Programs\zzz\clients.net\zzzNet.exe
AssemblyDirectory = C:\Programs\zzz\clients.net\
Application Config File = C:\Programs\zzz\clients.net\zzzNet.exe.Config
-----------------
INFO: Parsing Application Config File C:\Programs\zzz\clients.net\zzzNet.exe.Config.
INFO: Parsing Manifest File C:\Programs\zzz\clients.net\zzzNet.exe.
INFO: Manifest Definition Identity is (null).
ERROR: Line 0: XML Syntax error.
ERROR: Activation Context generation failed.
End Activation Context Generation.
It is quite simple .NET application (1 exe + 8 dll files). It was built for .NET 3.5 Client Profile.
I not defined any special "manifest" there. Just clicked "New Windows Forms Project" in Visual Studio and developed it.
Also app.config does not contain anything special - only primitive standard settings - appSettings and userSettings sections.
On PC where I developed it all is perfectly works. Problems only began when I copy these binaries to this particular VM and try to start.
Also please note - these executables were not installed in GAC or such, I just copied them into a folder on VM and started. And when it was 1st time all was working fine.
So, the problem pattern is following:
Copy .NET execuatbles to new VM (it is Win 7 x64), run it, all is working fine. Close it.
Build new version of .NET execuatbles on host PC, copy new .NET execuatbles to VM (with files overwriting).
Try to start - got mentioned problem.
After some shaman-style actions (like OS reboot, etc) it begin to work but why that happened at all?!
Why replacing .NET executables with new versions is causing SUCH HUGE PROBLEMS?!
Also the BIG QUESTION - is there any special procedure to replace .NET executables to keep them working? Because it is a new app development, I do not want lost so much time on every new executables installation. :-\
Could you please help? Because it looks completely weird!
Thank you in adance.
PS. I checked all VS projects - all they have PlatformTarget=AnyCPU. Also in run-time I can see ProcessType=MSIL (I show this info in AboutBox for application). So, there is no mix of x86/x64 binaries.
It seems that was related to mapped network drive behavior.
When I copied new files from network drive folder it copied wrong files - a strange random mess of new files and older ones (which were there before I updated them on VM host).
The scenario to make it working:
on VM: delete all files in a folder on network drive
on VM host: copy new files into a folder which is mapped as network drive on VM
on VM: copy files into target folder
on VM: run application - it works now
Weird thing. I remember I have seen something similar with Windows Explorer on Windows 2008 behaviour when copying updated win32 binaries.

MSBuild appending MSDEPLOYAGENTSERVICE to the end of my URL

I am trying to configure a build in TFS to deploy to our test box for continuous integration. The problem I'm having is that TFS wants to append the MSDEPLOYAGENTSERVICE to the end of my URL which is causing the deploy to return a socket error:
Retrying the sync because a socket error (10054) occurred. Retrying operation 'Serialization' on object sitemanifest (sourcePath).
Here are my MSBuild Arguments:
/p:DeployOnBuild=True
/p:DeployTarget=MSDeployPublish
/p:MsDeployServiceUrl=[ip address]:8172/MsDeploy.axd
/p:MSDeployPublishMethod=RemoteAgent
/p:CreatePackageOnPublish=True
The server is a Windows Server 2008 R2 64bit server with IIS 7.5. We have no problems using the publish feature of Visual Studio 2010 to deploy to the test box using the Url above. Any help would be much appreciated.
You don't need to specify MsDeploy.axd in your MsDeployServiceUrl. Also, I see you don't have a DeployIisAppPath value set. You should set it to the name of your website in IIS.
Below is an example from one of our CI builds.
/p:DeployOnBuild=True
/p:DeployTarget=MsDeployPublish
/p:CreatePackageOnPublish=True
/p:MSDeployPublishMethod=RemoteAgent
/p:MSDeployServiceUrl=http://[YOUR WEBSERVER URL]
/p:DeployIisAppPath="NAME-OF-WEBSITE-IN-IIS"
After a few days an tons of searching, I discovered the issue.
/p:DeployOnBuild=True
/p:DeployTarget=MSDeployPublish
/p:MsDeployServiceUrl=[ip address]/MsDeploy.axd
/p:MSDeployPublishMethod=WMSVC
/p:CreatePackageOnPublish=True
/p:DeployIisAppPath=[name of website in iis]
/p:AllowUntrustedCertificate=True
As it turns out, the publish method was the culprit. RemoteAgent cannot interpret the deploy correctly, which is why it fails to serialize. WMSVC is the appropriate setting for the publish method.

Categories