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

Field not found on .Flush in NUnit Console

Open davidhenderickx opened this issue 1 year ago • 7 comments

Hello,

I'm implementing extent with Selenium in C# .Net 8.0 I'm following this tutorial: https://www.youtube.com/watch?v=89YBs9mK9V8&list=PLaDALgeX9grofiW_34GGWY9JpTMfhSsfb&index=13 Instead of using the htmlreporter, I'm using sparkreporter since htmlreporter is depreciated

When running with > dotnet test, my tests run fine and the report gets created.

But, when I run with the NUnit console > nunit3-console.exe TA_Framework.dll, the .flush returns me the following error and no report is generated:

Field not found: 'AventStack.ExtentReports.Model.Context.Manager.NamedAttributeContextManager`1.Context'.
   at CompiledRazorTemplates.Dynamic.RazorEngine_de4fe5cd9fa1409f85e2a4d8a01fcda0.ExecuteAsync()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
   at CompiledRazorTemplates.Dynamic.RazorEngine_de4fe5cd9fa1409f85e2a4d8a01fcda0.ExecuteAsync()
   at RazorEngine.Templating.TemplateBase.Run(ExecuteContext context, TextWriter reader)
   at RazorEngine.Templating.RazorEngineCore.RunTemplate(ICompiledTemplate template, TextWriter writer, Object model, DynamicViewBag viewBag)
   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)
   at System.Reactive.Subjects.Subject`1.OnNext(T value)
   at AventStack.ExtentReports.Core.ReactiveSubject.Flush()
   at AventStack.ExtentReports.Core.AbstractProcessor.OnFlush()
   at AventStack.ExtentReports.ExtentReports.Flush()
   at Utils.Reports.Extent.ExtentReporter.EndReporting() in C:\Users\JX8198\Development\TA_Framework\Reporting\Extent\ExtentReporter.cs:line 92
   at TA_Framework.Tests.BaseTest.TestTeardown() in C:\Users\JX8198\Development\TA_Framework\Tests\BaseTest.cs:line 61

I tried it in version 5.0.0, 5.0.2 and 5.0.4, all of them have the same issue.

My .csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>disable</Nullable>
    <IsPackable>false</IsPackable>
    <IsTestProject>true</IsTestProject>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
    <PackageReference Include="NUnit" Version="3.13.3" />
    <PackageReference Include="NUnit.Console" Version="3.18.1" />
    <PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
    <PackageReference Include="NUnit.Analyzers" Version="3.6.1" />
    <PackageReference Include="coverlet.collector" Version="6.0.0" />
    <PackageReference Include="Selenium.Support" Version="4.23.0" />
    <PackageReference Include="Selenium.WebDriver" Version="4.23.0" />
    <PackageReference Include="ExtentReports" Version="5.0.0" />
    <PackageReference Include="NLog" Version="5.3.2" />
  </ItemGroup>
</Project>

davidhenderickx avatar Aug 14 '24 13:08 davidhenderickx

I have also run into this error. ExtentReports flushes ok when run from VS UI, or with dotnet test. Not with nunit3-console.exe, same error.

joshuafontany avatar Oct 02 '24 23:10 joshuafontany

@anshooarora can you please prioritize this issue. we cant update to nunit 4 \ .net8.0 because of this.

kv-naveen avatar Oct 18 '24 13:10 kv-naveen

I have the same issue. updated from .net6 to .Net 8 . Nunit Console runner 3.18. ExtentReport version 5.0.4 Error: TearDown : System.MissingFieldException : Field not found: 'AventStack.ExtentReports.Model.Context.Manager.NamedAttributeContextManager1.Context'. --TearDown at CompiledRazorTemplates.Dynamic.RazorEngine_4bab4e82015f4cea855aba26e118c869.ExecuteAsync() at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) at CompiledRazorTemplates.Dynamic.RazorEngine_4bab4e82015f4cea855aba26e118c869.ExecuteAsync() at RazorEngine.Templating.TemplateBase.Run(ExecuteContext context, TextWriter reader) at RazorEngine.Templating.RazorEngineCore.RunTemplate(ICompiledTemplate template, TextWriter writer, Object model, DynamicViewBag viewBag) 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(Action1 withWriter) at RazorEngine.Templating.RazorEngineServiceExtensions.RunCompile(IRazorEngineService service, String name, Type modelType, Object model, DynamicViewBag viewBag) at AventStack.ExtentReports.Reporter.ExtentSparkReporter.OnNext(ReportEntity value) at System.Reactive.Subjects.Subject1.OnNext(T value) at AventStack.ExtentReports.Core.ReactiveSubject.Flush() at AventStack.ExtentReports.Core.AbstractProcessor.OnFlush() at AventStack.ExtentReports.ExtentReports.Flush() at TechnoModule.BaseContext.TearDown() in C:\sourceCodeGit\CyberquantQA\AutomationE2E\TechnoModule\baseContext\BaseContext.cs:line 331 at NUnit.Framework.Internal.TaskAwaitAdapter.GenericAdapter1.GetResult() at NUnit.Framework.Internal.AsyncToSyncAdapter.Await[TResult](Func1 invoke) at NUnit.Framework.Internal.AsyncToSyncAdapter.Await(Func1 invoke) at NUnit.Framework.Internal.Commands.SetUpTearDownItem.RunSetUpOrTearDownMethod(TestExecutionContext context, IMethodInfo method) at NUnit.Framework.Internal.Commands.SetUpTearDownItem.RunTearDown(TestExecutionContext context)

Yuliagrin avatar Nov 05 '24 08:11 Yuliagrin

I am seeing the same issue. Runs fine via VS UI but not with the nunit console.

michaelchambers324 avatar Nov 15 '24 17:11 michaelchambers324

Hi everyone. I have exact the same issue.

ExtentReports - 5.0.4 NUnit console - 3.18.1

Zhuraulevich911 avatar Jun 18 '25 11:06 Zhuraulevich911

Any estimates on this ? Have exact same behavior.

ExtentReports - 5.0.4 NUnit console - 3.18.1

PSeledkin avatar Jul 23 '25 09:07 PSeledkin

@PSeledkin , @Zhuraulevich911 , @michaelchambers324 , @Yuliagrin , @kv-naveen , @davidhenderickx

I resolved this by moving away from NUnit Console, and just running the tests with & dotnet test $testDLL (I am on dotnet6.0).

This allows ExtentReport to cleanly export the final HTML.

Then I also needed to use the NunitXml.TestLogger package in every Test Project in order to get the XML results for automation.

joshuafontany avatar Jul 23 '25 15:07 joshuafontany