Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Code Analysis CA1307 & CA1310 not working in new .NET 6 projects

I’m using Visual Studio 2022 (17.4.4), and when I create a new empty .NET 6 project, Code Analysis doesn’t work.

According to MSDN, Roslyn Code Analyzers are automatically enabled for every new .NET 6 project:

Starting in Visual Studio 2019 16.8 and .NET 5.0, these analyzers are
included with the .NET SDK. Analysis is enabled, by default, for
projects that target .NET 5.0 or later.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Here’s the steps I followed:

  1. Start Visual Studio
  2. Create a new .NET 6 Console Project
  3. Paste the code below
  4. Click Analyze -> Run Code Analysis. I would expect to get CA1307 or CA1310 – however, I get neither.

How can I get Code Analysis to work here?

Console.WriteLine("asdf".IndexOf("/")); // expecting CA1307 or CA1310 here
Console.WriteLine("Hello, World!");

>Solution :

Since 5.0 CA1307 is Disabled and CA13010 is Hidden you can have a complete view of Roslyn rules here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading