Can someone help with a Playwright .NET and Extent Reports issue?

Apologies if this is not the correct use of this forum but I am really struggling…

I have a Playwright project set up using C# and I’m trying to get Extent Reports working. (I realise C# is not the best choice for Playwright but this is out of my control just now).

When I run the test I get this error, 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? Has anyone come across this issue before, or able to offer any guidance?

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:


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();
}

Thanks very much and apologies again if this is not correct use of this forum.

Hi

I don’t use either Playwrite or C# myself, but I did a bit of searching and reading and maybe the following might help:

It looks like there could be a version mismatch between the assemblies your application is referencing

Given the package references you’ve provided, there seems to be a version mismatch issue, particularly between Microsoft.AspNetCore.Mvc.Testing (version 8.0.8) and Microsoft.AspNetCore.Razor.Language (version 6.0.33). Microsoft.AspNetCore.Mvc.Testing version 8.x is designed to work with .NET 8, while Microsoft.AspNetCore.Razor.Language version 6.x is tied to .NET 6.

You could try to align all packages to either .NET 6 or .NET 8.

Thank you so much for taking the time to investigate. I did wonder if it was a version mismatch but wasn’t sure how to find out. The application I’m testing is using .NET8 so I’m assuming I can’t use Extent Reports in that case, since I need the Razor.Language package for this to work and it’s not compatible. Guess I need to find another type of report to use :pensive: thanks again for your help

There are apparently .net 6 to .net 8 migration guides that include the above.

From what I have read (with limited knowledge) Microsoft.AspNetCore.Razor.Language can be used with .net 8 but requires a few changes as part of the migration.

I believe this is the command to get the updated version.

dotnet add package Microsoft.AspNetCore.Razor.Language --version 8.0.0

I really don’t know enough about this to suggest exactly how to do this, but hopefully, this information helps.