Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CA1416 warnings when using .NET 8 with WinForms

I have an older WinForms application that I'm updating from .NET 6 to .NET 8.

<PropertyGroup>
  <OutputType>WinExe</OutputType>
  <TargetFramework>net8.0-windows</TargetFramework>
  <UseWindowsForms>true</UseWindowsForms>
  <Nullable>enable</Nullable>
  <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>

But now I get hundreds of errors, such as the following.

3>C:\Users\jwood\Source\Repos\SoftCircuits\HtmlMonkey\TestHtmlParse\HtmlVisualizer.cs(92,21,92,40): warning CA1416: This call site is reachable on all platforms. 'ListView.Items' is only supported on: 'windows' 6.1 and later. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
3>C:\Users\jwood\Source\Repos\SoftCircuits\HtmlMonkey\TestHtmlParse\NodeVisualizer.cs(157,30,157,62): warning CA1416: This call site is reachable on all platforms. 'ListView.ColumnHeaderCollection.Add(string?)' is only supported on: 'windows' 6.1 and later. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
3>C:\Users\jwood\Source\Repos\SoftCircuits\HtmlMonkey\TestHtmlParse\NodeVisualizer.cs(154,13,154,27): warning CA1416: This call site is reachable on all platforms. 'ListView.Items' is only supported on: 'windows' 6.1 and later. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
3>C:\Users\jwood\Source\Repos\SoftCircuits\HtmlMonkey\TestHtmlParse\HtmlVisualizer.cs(86,21,86,33): warning CA1416: This call site is reachable on all platforms. 'TextBox.Text' is only supported on: 'windows' 6.1 and later. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
3>C:\Users\jwood\Source\Repos\SoftCircuits\HtmlMonkey\TestHtmlParse\NodeVisualizer.cs(157,30,157,46): warning CA1416: This call site is reachable on all platforms. 'ListView.Columns' is only supported on: 'windows' 6.1 and later. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
3>C:\Users\jwood\Source\Repos\SoftCircuits\HtmlMonkey\TestHtmlParse\NodeVisualizer.cs(158,17,158,29): warning CA1416: This call site is reachable on all platforms. 'ColumnHeader.Width' is only supported on: 'windows' 6.1 and later. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

I don't really understand what is going on here. My solution includes non-WinForms projects, but I don't see how that could cause this error about being reachable on all platforms.

I tested and it works fine with net7.0-windows. I'm running on Windows 11.

Does anyone know why I'm getting this error with .NET 8?

like image 207
Jonathan Wood Avatar asked Oct 16 '25 00:10

Jonathan Wood


2 Answers

I don't know why Microsoft didn't provide an easy workaround for this breaking change. I tried the suggested fixes but it only caused other problems.

I was able to fix it by creating a new WinForms project using .NET 8, and then copying over the files to the new project. That fix works for me.

like image 107
Jonathan Wood Avatar answered Oct 17 '25 14:10

Jonathan Wood


I had the same issues after Upgrading projects from .NET Framework to .NET 6.0. In my case it helped cleaning up the .csproj file from unused propertys.

Especially after removing this code all warnings disappeared.

<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
like image 37
Stan1k Avatar answered Oct 17 '25 14:10

Stan1k