.NET 7 warning: use ‘GeneratedRegexAttribute’ (SYSLIB1045)

.NET 7 introduced the [GeneratedRegex] attribute that allows doing some regex initialization in compile time rather than in runtime. Using this attribute might help improve performance. Therefore some tooling might start showing you a warning that you miss an opportunity for free performance gains 🙂 SYSLIB1045 Use ‘GeneratedRegexAttribute’ to generate the regular expression implementation at … Read more

Migrate from Jetbrains.Annotations [NotNull] / [CanBeNull] to C# Nullable Reference Types

The most popular feature of JetBrains.Annotations is probably the addition of two cool attributes: [NotNull] and [CanBeNull]. They add a meta-information to a marked element, describing if null is a correct value for that element, or not. Then, developers using ReSharper would get help from the IDE and could easier avoid mistakes like here: I … Read more

Moq: Extension methods (here: LoggerExtensions.LogError) may not be used in setup / verification expressions.

Sometimes when we develop unit tests it’s convenient to check if the tested code wrote something to the log. Is it a good practice to assert that some particular message appeared in the logs? I think there are pros and cons. On the pros side, we can make general assertions like “no errors were written … Read more

Error CS0618: ‘ConsoleLogger’ is obsolete

This is a short note showing my fix to an error I encountered when migrating application from .NET Framework to the most recent (at the moment) .NET 6. I’m just pasting the rough code example of how this can be migrated, because: Custom console logger using old Microsoft.Extensions.Logging.Console 2.1.1 Equivalent custom console logger using newer Microsoft.Extensions.Logging.Console 6.0.0 … Read more