Menu
Microsoft .NET 5 adds safe warnings for C#

Microsoft .NET 5 adds safe warnings for C#

New AnalysisLevel in the C# compiler introduces warnings for common coding mistakes and other latent bugs in a safe way

Credit: Dreamstime

Microsoft’s planned .NET 5 software development platform produces safe warnings for the C# compiler and automatically finds latent bugs.

With .NET 5, a new capability called AnalysisLevel introduces warnings in a way that alerts developers that something is wrong. The default AnalysisLevel for all projects targeting .NET 5 will be set to 5, which provides new compiler language analysis. This means that more warnings and suggestions to fix them will be introduced.

Microsoft has had many instances over the years where it wanted to provide warnings that something was wrong with a C# coding project, ranging from common coding mistakes to API misuse patterns.

But the company has been reluctant to do so because of the breaking change issue. With AnalysisLevel, warnings are introduced for patterns in a safe way.

.NET 5 currently is in a preview stage, with the production version due in November. The company detailed its C# compiler warnings plan in a bulletin posted on August 27. The bulletin noted that all new .NET projects will be opted into AnalysisLevel 5. Here are some new level 5 warnings and suggestions for .NET 5:

  • CA1416, an interoperability warning to warn when code does not work across all platforms
  • CA2247, a usage warning rethrow to preserve stack details
  • CSO185, a correctness error to not allow locks on non-reference types

Previously, .NET required the installation of NuGet packages or other standalone tools to enable deeper code analysis. The .NET 5 SDK provides this automatically. Future plans call for a new AnalysisLevel for every release of .NET. This is intended to ensure that a given analysis level always represents the same set of analysis defaults — the rules and their severities.

Turning on an existing rule by default would be done in an upcoming AnalysisLevel instead of changing the existing level. This ensures that a given project produces the same warning regardless of the SDK version, unless the project uses preview or latest.


Follow Us

Join the newsletter!

Or

Sign up to gain exclusive access to email subscriptions, event invitations, competitions, giveaways, and much more.

Membership is free, and your security and privacy remain protected. View our privacy policy before signing up.

Error: Please check your email address.

Tags Microsoft

Featured

Slideshows

The Kiwi channel gathers for the 2020 Reseller News Women in ICT Awards

The Kiwi channel gathers for the 2020 Reseller News Women in ICT Awards

Hundreds of leaders from the New Zealand IT industry gathered at the Hilton in Auckland on 17 November to celebrate the finest female talent in the Kiwi channel and recognise the winners of the Reseller News Women in ICT Awards (WIICTA) 2020.

The Kiwi channel gathers for the 2020 Reseller News Women in ICT Awards
Leading female front runners honoured at the 2020 Reseller News Women in ICT Awards

Leading female front runners honoured at the 2020 Reseller News Women in ICT Awards

The leading female front runners of the New Zealand ICT industry joined together for the annual Reseller News Women in ICT Awards event at the Hilton in Auckland, during which hundreds of guests celebrated 13 outstanding individuals who won awards, chosen from more than 50 finalists representing over 30 organisations.

Leading female front runners honoured at the 2020 Reseller News Women in ICT Awards
Channel gathers to celebrate the Reseller News Innovation Awards 2020 winners

Channel gathers to celebrate the Reseller News Innovation Awards 2020 winners

More than 500 channel leaders gathered in Auckland on 21 October at the ​Reseller News Innovation Awards ​2020 to celebrate the achievements of the New Zealand technology industry's top partners, start-ups, vendors, distributors and individuals.

Channel gathers to celebrate the Reseller News Innovation Awards 2020 winners
Show Comments