extentreports-csharp icon indicating copy to clipboard operation
extentreports-csharp copied to clipboard

How to handle System.OutOfMemoryException Error

Open JonnySunNZ opened this issue 3 years ago • 0 comments

Hi,

I'm working on an automation suite that has nearly a thousand tests and also several base64 images written to report. However, it will throw OutOfMemoryException when calling Flush() to generate the report:

Assembly Cleanup method Automation_MSTestAssemblyHooks.AssemblyCleanup failed. Error Message: System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.. StackTrace:     at System.Text.StringBuilder.ToString()
   at RazorEngine.Templating.TemplateBase.<Run>d__32.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at RazorEngine.Templating.RazorEngineService.Run(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.DynamicWrapperService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineServiceExtensions.RunCompile(IRazorEngineService service, String name, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass16_0.<RunCompile>b__0(TextWriter writer)
   at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
   at RazorEngine.Templating.RazorEngineServiceExtensions.RunCompile(IRazorEngineService service, String name, Type modelType, Object model, DynamicViewBag viewBag)
   at AventStack.ExtentReports.Reporter.ExtentSparkReporter.OnNext(ReportEntity value) in /Users/anshooarora/Documents/GitHub/extent-framework/extentreports-csharp/ExtentReports/Reporter/ExtentSparkReporter.cs:line 78
   at System.Reactive.Subjects.Subject`1.OnNext(T value) in /_/Rx.NET/Source/src/System.Reactive/Subjects/Subject.cs:line 147
   at AventStack.ExtentReports.Core.ReactiveSubject.Flush() in /Users/anshooarora/Documents/GitHub/extent-framework/extentreports-csharp/ExtentReports/Core/ReactiveSubject.cs:line 20
   at AventStack.ExtentReports.Core.AbstractProcessor.OnFlush() in /Users/anshooarora/Documents/GitHub/extent-framework/extentreports-csharp/ExtentReports/Core/AbstractProcessor.cs:line 106
   at AventStack.ExtentReports.ExtentReports.Flush() in /Users/anshooarora/Documents/GitHub/extent-framework/extentreports-csharp/ExtentReports/Core/ExtentReports.cs:line 84
   at Automation.Common.TestBase.AfterTestRun() in C:\Automation\Common\TestBase.cs:line 38
   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.FireEvents(HookType hookType) in D:\a\1\s\TechTalk.SpecFlow\Infrastructure\TestExecutionEngine.cs:line 367
   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnTestRunEnd() in D:\a\1\s\TechTalk.SpecFlow\Infrastructure\TestExecutionEngine.cs:line 138
   at TechTalk.SpecFlow.TestRunnerManager.FireTestRunEnd() in D:\a\1\s\TechTalk.SpecFlow\TestRunnerManager.cs:line 110
   at TechTalk.SpecFlow.TestRunnerManager.OnTestRunEnd(Assembly testAssembly, IContainerBuilder containerBuilder) in D:\a\1\s\TechTalk.SpecFlow\TestRunnerManager.cs:line 224
   at Automation_MSTestAssemblyHooks.AssemblyCleanup() in C:\Automation\obj\x64\Debug\MSTest.AssemblyHooks.cs:line 31

The project's target platform is set to x64 and the following attribute is added to app.config

<configuration>  
  <runtime>  
    <gcAllowVeryLargeObjects enabled="true" />  
  </runtime>  
</configuration>  

Please help, thanks in advance!

JonnySunNZ avatar Apr 01 '22 04:04 JonnySunNZ