I’m encountering a critical issue while generating RDLC reports in my .NET application. My tech stack includes .NET and Visual Studio 2022. Every time I attempt to generate a report, I receive the following error:
Managed Debugging Assistant ‘FatalExecutionEngineError’
Message=Managed Debugging Assistant ‘FatalExecutionEngineError’ : ‘The runtime has encountered a fatal error. The address of the error was at 0x74688b02, on thread 0x3ed0. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.’
This error causes the application to break into debug mode. After debugging, I pinpointed the error to the following line of code within the RenderReportInBackground method:
byte[] bytes = reportViewer.Render(reportFormat, deviceInfo, out mimeType, out encoding, out extension, out streamids, out warnings);
Here are the details of the method:
public static byte[] RenderReportInBackground(LocalReport reportViewer, string reportFormat, out string mimeType, out string fileNameExtension)
{
try
{
Warning[] warnings;
string[] streamIds;
string encoding;
string deviceInfo;
switch (reportFormat.ToUpper())
{
case "PDF":
deviceInfo = "<DeviceInfo><OutputFormat>PDF</OutputFormat></DeviceInfo>";
mimeType = "application/pdf";
fileNameExtension = "pdf";
break;
case "EXCEL":
deviceInfo = "<DeviceInfo><SimplePageHeaders>False</SimplePageHeaders></DeviceInfo>";
mimeType = "application/vnd.ms-excel";
fileNameExtension = "xlsx";
break;
default:
deviceInfo = "<DeviceInfo><OutputFormat>PDF</OutputFormat></DeviceInfo>";
mimeType = "application/pdf";
fileNameExtension = "pdf";
break;
}
return reportViewer.Render(reportFormat, deviceInfo, out mimeType, out encoding, out fileNameExtension, out streamIds, out warnings);
}
catch (Exception ex)
{
ex.WriteLog();
mimeType = "application/pdf";
fileNameExtension = "";
return new byte[0];
}
}
Development Environment:
- Visual Studio 2022
- .NET Framework 4.8
- RDLC Report Designer V15.3.1
Error Context:
The error occurs during the report generation process.
The error points to a potential issue with the CLR or unsafe code portions.
The error code is 0xc0000005.
Troubleshooting Steps Taken:
- Verified that all necessary NuGet packages are up-to-date.
- Checked for any issues in the RDLC report definition.
- Confirmed that the LocalReport object is properly initialized and configured.
- Open the properties for the project, go to the Build tab and check the Allow unsafe code checkbox.
Despite these efforts, the issue persists. Can someone please provide guidance on how to resolve this error? Are there specific debugging steps or tools I should use to diagnose the root cause?
Thank you for your assistance!