Passing test locally, failing on Exercism (GeneratedRegex)

I’m not sure how to deal with this, any help would be appreciated. All the tests for my solution pass locally but fail once I submit the solution.

This is for the “Log Levels” exercise in the C# track. The exercise has a project file that specifies the “net8.0” framework, and that is what I am using locally:

❯ dotnet --list-sdks
6.0.425 [C:\Program Files\dotnet\sdk]
7.0.410 [C:\Program Files\dotnet\sdk]
8.0.108 [C:\Program Files\dotnet\sdk]

I can run the tests and they all pass:

❯ exercism test
Running tests via `dotnet test`

  Determining projects to restore...
  All projects are up-to-date for restore.
  LogLevels -> C:\Users\logavanc\Workspace\exercism.org\csharp\log-levels\bin\Debug\net8.0\LogLevels.dll
Test run for C:\Users\logavanc\Workspace\exercism.org\csharp\log-levels\bin\Debug\net8.0\LogLevels.dll (.NETCoreApp,Version=v8.0)
Microsoft (R) Test Execution Command Line Tool Version 17.8.0 (x64)
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.

Passed!  - Failed:     0, Passed:    11, Skipped:     0, Total:    11, Duration: 29 ms - LogLevels.dll (net8.0)

But when I upload:

We received the following error when we ran your code:

LogLevels.cs(6,34): error CS8795: Partial method 'LogLine._logLineRegex()' must have an implementation part because it has accessibility modifiers.

My solution is using a .NET regular expression source generator:

using System.Text.RegularExpressions;

static partial class LogLine
{
    [GeneratedRegex(@"^\[(?<level>.*)\]:(?<message>.*)$")]
    private static partial Regex _logLineRegex();
    public static string Message(string logLine) => _logLineRegex().Match(logLine).Groups["message"].Value.Trim();
    public static string LogLevel(string logLine) => _logLineRegex().Match(logLine).Groups["level"].Value.Trim().ToLower();
    public static string Reformat(string logLine) => $"{Message(logLine)} ({LogLevel(logLine)})";
}

Am I missing something obvious?

We don’t (yet) support GeneratedRegex, sorry.

1 Like