extent-framework/extentreports-csharp

Error with ExtentReports Flush and Razor

Opened this issue · 0 comments

I have receiving the below error when I run my test. It is complaining about the TearDown FlushReport function:

TearDown : System.TypeLoadException : Could not load type 'Microsoft.AspNetCore.Razor.Language.RazorTemplateEngine' from assembly 'Microsoft.AspNetCore.Razor.Language, Version=6.0.33.0

I understand it may be caused by incompatible package versions but I am new to coding and don’t know how I know what is or isn’t compatible?

These are my nuget package versions:

<PackageReference Include="ExtentReports" Version="4.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Language" Version="6.0.33" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="Microsoft.Playwright.NUnit" Version="1.46.0" />
<PackageReference Include="Microsoft.Playwright.TestAdapter" Version="1.46.0" />
<PackageReference Include="NUnit" Version="4.1.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.3.0">

And my code (ExtentReport.cs):

public static void InitialiseReport()
{
    string dir = AppDomain.CurrentDomain.BaseDirectory;
    string testReportPath = dir.Replace("bin\\Debug\\net8.0", "TestResults " + DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss"));
    string reportName = "Test Report" + DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss");

    ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter(testReportPath);
    htmlReporter.Config.DocumentTitle = reportName;
    _extentReports = new ExtentReports();
    _extentReports.AttachReporter(htmlReporter);
}

public static void FlushReport()
{
    _extentReports.Flush();
}

And the test file TearDown that utilises this file, this is where the error is occurring:

 [TearDown]
 public void TearDown()
 {
     var status = TestContext.CurrentContext.Result.Outcome.Status;
     var stackTrace = TestContext.CurrentContext.Result.StackTrace;
     var errorMessage = TestContext.CurrentContext.Result.Message;

     switch(status)
     {
         case TestStatus.Failed:
             ExtentReport._test.Log(Status.Fail, "Test failed: " + errorMessage);
             ExtentReport._test.Log(Status.Fail, "Stack Trace: " + stackTrace);
             break;
         case TestStatus.Inconclusive:
             ExtentReport._test.Log(Status.Warning, "Test inconclusive");
             break;
         case TestStatus.Skipped:
             ExtentReport._test.Log(Status.Skip, "Test skipped");
             break;
         default:
             ExtentReport._test.Log(Status.Pass, "Test passed");
             break;
     }

     ExtentReport.FlushReport();
 }

 [OneTimeTearDown]
 public void OneTimeTearDown()
 {
     ExtentReport.FlushReport();
     _driver.Dispose();
 }