.NET Adds Latent Bug Discovery Feature
Written by Kay Ewbank   
Friday, 11 September 2020

Microsoft has added a new set of warnings for common coding mistakes and API misuse patterns. The warnings will be introduced in the C# compiler in .NET 5.

The development team says that the .NET platform already includes "rich diagnostics and code suggestions in the .NET SDK by default", but that if you wanted more code analysis, until now you'd need to install NuGet packages or other stand-alone tools.

net2

.NET 5 is a combination of .NET Framework and .NET Core that aims to unify the .NET platform. The new version is due for general availability in November.

The team was reluctant to add new warnings to C# because it would cause code to stop as broken for users who have warnings set as errors. However, because a lot of code really does need the warnings, the team has added a new level for the AnalysisLevel to the C# compiler.

The default Analysis Level for all projects targeting .NET 5 will be set to 5, meaning that more warnings (and suggestions to fix them) will be introduced. You can set this to a lower level to avoid triggering warnings from within Visual Studio via the Code Analysis property page.

One aspect that s interesting about the new analysis level is the type of coding errors that Microsoft's research has shown they need to check for. Some are obvious - warn when an expression is always true or false, for example, along with a warning when code uses as or is on static types, or tries to put a lock on non-reference types.

Other no-nos that are flagged in the new warning include the use of rethrow on an exception incorrectly by including the variable of the exception so it changes stack details; and accidentally comparing a struct by reference.

Other warnings point out incorrect .NET API usage, and a number to help with low level coding to avoid problems due to trying to write code for high-performance applications that breaches safety considerations.

In the future Microsoft plans to add a new analysis level for every release of .NET. The goal is to make sure that a given analysis level always represents the same set of analysis defaults (the rules and their severities). This means that Microsoft will have a way to turn an existing rule on by default by doing it as a new analysis level rather than changing the existing level.

net2 

More Information

Microsoft Developer Blog Post On Latency Bug Checking

Related Articles

.NET Is One With .NET 5

Have Your Say On .NET For Spark 

 

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

Banner


Generative AI Training For All On Coursera
04/03/2024

Generative AI is on the loose, getting into business and commerce as well as into art, poetry and coding. Already useful, it  will become ever more useful as long as we use it properly. Coursera  [ ... ]



Quantum Computers Really Are A One Trick Pony
17/03/2024

Google is offering $5 million if you can think up a use for a quantum computer. Wait, I thought quantum computers were the next big thing, a revolution! Surely we know what they can do?


More News

raspberry pi books

 

Comments




or email your comment to: comments@i-programmer.info