To get a trial key
fill out the form below
Team License (standard version)
Enterprise License (extended version)
* By clicking this button you agree to our Privacy Policy statement

** This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
GBP
RUB
* By clicking this button you agree to our Privacy Policy statement

** This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
Message submitted.

Your message has been sent. We will email you at


If you haven't received our response, please do the following:
check your Spam/Junk folder and click the "Not Spam" button for our message.
This way, you won't miss messages from our team in the future.

>
>
>
Finally! PVS-Studio Supports .NET 5 Pro…

Finally! PVS-Studio Supports .NET 5 Projects

April 21, 2021

On November 10th, 2020, Microsoft released a new version of .NET Core - .NET 5. The updated platform presents many new enhancements. For example, it allows C# developers to use features the new C# 9 offers: records, relational pattern matching, etc. Unfortunately, there was a disadvantage: PVS-Studio could not analyze these projects. However (and here's the good news)... That used to be the case :) Our next release, PVS-Studio 7.13, will support projects that target .NET 5.

0822_NET_5_support/image1.png

Aka .NET Core 4

.NET 5 is the next step after .NET Core 3.1. We can see that Microsoft changed the name from .NET Core to .NET. This is to show that they will focus on this platform further on. Microsoft basically confirmed this on their official website – they've already posted three preview versions of .NET 6 there.

But why did the version number go from 3.1 to 5? This does not seem surprising - remember how Windows 10 followed Windows 8.1? :)

In fact, Microsoft skipped number 4 to avoid confusion between .NET Framework and .NET. However, "Entity Framework Core 5.0", based on .NET 5, will keep its "Core" postfix. Otherwise it would not be possible to differentiate between Core and Framework versions of "Entity Framework 5.0".

.NET 5 supplies developers with many new tools. For example, C# now offers an enhanced pattern matching mechanism. Then there is this unusual and interesting feature that enables you to write code outside of functions or classes. Not every developer needs this capability, but it's bound to attract some fans. A full list of C# 9 enhancements is available on Microsoft's official website.

You can read about new features in .NET 5 here.

PVS-Studio and .NET 5

We received many requests from our clients to support .NET 5 projects. We also understood that the analyzer must support the latest innovations. However, although important, new .NET versions are not PVS-Studio's only direction for development. This is why it took us a while to present our new version that supports .NET 5 projects.

The upgrade concerns our analyzer versions for Windows, Linux and macOS. PVS-Studio for Windows still requires .NET Framework 4.7.2. On Linux and macOS, the analyzer now requires .NET 5. Previously, .NET Core 3.1 was sufficient.

Why did we switch the analyzer for Linux and macOS to .NET 5?

Our initial plan was to switch the analyzer from .NET Core 3.1 to .NET 5 at a later time. However, this had to change when we encountered a problem.

When analyzing projects for .NET Core or .NET 5, PVS-Studio actively interacts with the corresponding version's SDK. The tricky thing is, .NET 5 SDK libraries depend on the .NET 5 version's "System.Runtime" library. Meanwhile, if the analyzer targets .NET Core 3.1, it loads the 3.1 version's "System.Runtime" library. As a result, we kept getting a conflict - the analyzer could not interact with the SDK library, and the analysis was not possible.

Switching from .NET Core to .NET 5 completely resolved this problem. :)

Instantaneous Enhancements

To support .NET 5 project analysis we needed to update some dependencies. Specifically, PVS-Studio now uses newer Roslyn and MSBuild versions. This enables the analyzer to process code, that uses C# 9 features, correctly. For example, the code below could trigger false warnings:

user = user with { Name = "Bill" }

The analyzer did not have any information about WithExpression - and thus could not process this code correctly. As a result the analyzer issued a warning that the user variable was assigned to itself. Of course, the analysis report also contained a warning that the analyzer did not support this project. However, the latter did not make things easier. :( Luckily, the new update fixed the problem automatically. Other problems we had to fix manually.

Problems with New Versions

To stay up-to-date, the static analyzer needs to adapt to new language versions. The analyzer's developers cannot foresee all features a language may get in the future. To support a new language version, the analyzer needs more than just correct parsing and semantics structure. The analyzer's developers also need to review the tool's code, evaluate the use of various internal technologies and diagnostic rules. The analyzer will likely require additional changes after a new language version comes out.

One of the new - and problematic - C# features is top-level statements. When working on the C# analyzer, we expected that local variables, conditions, loops, etc. are always inside methods. Now that you can write C# code even without declaring a class... Obviously, this is something very interesting, but it creates some problems for us. Though we doubt that all developers will start to write all code outside of classes. :)

Another new feature that prompted us to change our tool's code is the init accessor. We had to rework the V3140 diagnostic rule.

The rule is triggered when a property's accessors use different internal variables. The code sample below (from the RunUO Check article) triggers this diagnostic:

private bool m_IsRewardItem;

[CommandProperty( AccessLevel.GameMaster )]
public bool IsRewardItem
{
  get{ return m_IsRewardItem; }
  set{ m_IsRewardItem = value; InvalidateProperties(); }
}

private bool m_East;

[CommandProperty( AccessLevel.GameMaster )]
public bool East                                       // <=
{
  get{ return m_East; }
  set{ m_IsRewardItem = value; InvalidateProperties(); } 
}

PVS-Studio warns: V3140 Property accessors use different backing fields. WallBanner.cs 77

When writing the V3140 diagnostic, we assumed that a property can have only two accessors - get and set. The new init accessor went outside this expectation. This did not just cause the diagnostic's incorrect operation - the diagnostic kept crashing and throwing an exception! Luckily, we caught this problem when testing - and fixed it successfully.

0822_NET_5_support/image2.png

Can't Wait for the Release?

You do not have to wait! Of course, now it's not too long before the release, but still... Don't you want to try the new version as soon as possible? No problem - we are eager to help! Go to the feedback page and request the new version. We'll try to respond as soon as possible - which means soon you can analyze your (and not yours only) .NET 5 projects!

We also encourage you to share your impression about PVS-Studio. Whatever your experience with the analyzer, we would like to know about it. After all, it is largely thanks to user reviews that PVS-Studio develops and becomes better.

Popular related articles
Free PVS-Studio for those who develops open source projects

Date: 12.22.2018

Author: Andrey Karpov

On the New 2019 year's eve, a PVS-Studio team decided to make a nice gift for all contributors of open-source projects hosted on GitHub, GitLab or Bitbucket. They are given free usage of PVS-Studio s…
The Evil within the Comparison Functions

Date: 05.19.2017

Author: Andrey Karpov

Perhaps, readers remember my article titled "Last line effect". It describes a pattern I've once noticed: in most cases programmers make an error in the last line of similar text blocks. Now I want t…
The way static analyzers fight against false positives, and why they do it

Date: 03.20.2017

Author: Andrey Karpov

In my previous article I wrote that I don't like the approach of evaluating the efficiency of static analyzers with the help of synthetic tests. In that article, I give the example of a code fragment…
The Ultimate Question of Programming, Refactoring, and Everything

Date: 04.14.2016

Author: Andrey Karpov

Yes, you've guessed correctly - the answer is "42". In this article you will find 42 recommendations about coding in C++ that can help a programmer avoid a lot of errors, save time and effort. The au…
Static analysis as part of the development process in Unreal Engine

Date: 06.27.2017

Author: Andrey Karpov

Unreal Engine continues to develop as new code is added and previously written code is changed. What is the inevitable consequence of ongoing development in a project? The emergence of new bugs in th…
How PVS-Studio Proved to Be More Attentive Than Three and a Half Programmers

Date: 10.22.2018

Author: Andrey Karpov

Just like other static analyzers, PVS-Studio often produces false positives. What you are about to read is a short story where I'll tell you how PVS-Studio proved, just one more time, to be more atte…
Appreciate Static Code Analysis!

Date: 10.16.2017

Author: Andrey Karpov

I am really astonished by the capabilities of static code analysis even though I am one of the developers of PVS-Studio analyzer myself. The tool surprised me the other day as it turned out to be sma…
Technologies used in the PVS-Studio code analyzer for finding bugs and potential vulnerabilities

Date: 11.21.2018

Author: Andrey Karpov

A brief description of technologies used in the PVS-Studio tool, which let us effectively detect a large number of error patterns and potential vulnerabilities. The article describes the implementati…
PVS-Studio for Java

Date: 01.17.2019

Author: Andrey Karpov

In the seventh version of the PVS-Studio static analyzer, we added support of the Java language. It's time for a brief story of how we've started making support of the Java language, how far we've co…
PVS-Studio ROI

Date: 01.30.2019

Author: Andrey Karpov

Occasionally, we're asked a question, what monetary value the company will receive from using PVS-Studio. We decided to draw up a response in the form of an article and provide tables, which will sho…

Comments (0)

Next comments

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
This website uses cookies and other technology to provide you a more personalized experience. By continuing the view of our web-pages you accept the terms of using these files. If you don't want your personal data to be processed, please, leave this site.
Learn More →
Accept