Why green squiggly line creating Font variable?

Nicholas Piazza 531 Reputation points
2021-12-01T21:33:59.817+00:00

I am writing a .NET 6 Windows Forms application. See the project file below.

<!-- Replace ProjectName and SolutionName -->  
<Project Sdk="Microsoft.NET.Sdk">  
	<PropertyGroup>  
		<TargetFrameworks>net6.0-windows</TargetFrameworks>  
		<LangVersion>10</LangVersion>  
		<OutputType>winexe</OutputType>  
		<UseWindowsForms>true</UseWindowsForms>  
		<GenerateAssemblyInfo>false</GenerateAssemblyInfo>  
		<AssemblyName>MathHelper</AssemblyName>  
		<RootNamespace>MathHelper</RootNamespace>  
		<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>  
	</PropertyGroup>  
  <ItemGroup>  
    <Reference Include="MyLibrary">  
      <HintPath>..\..\MyLibrary\MyLibrary\obj\Debug\net6.0\MyLibrary.dll</HintPath>  
    </Reference>  
  </ItemGroup>  
</Project>  

In one of my methods is the following line:

Font selectionFont = new (FontFamily.GenericMonospace,8f);

In that line, 'new (FontFamily.GenericMonospace,8f);' is underlined with a green squiggly. Hovering over that line displays the following information:

154190-greenline.png

I don't understand the information and despite the green squiggly, the application compiles and runs. What is wrong with that Font creation?

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,218 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Jack J Jun 24,286 Reputation points Microsoft Vendor
    2021-12-02T05:40:07.01+00:00

    @Nicholas Piazza , Based on my research, It violates the Rule CA1416.

    The article CA1416: Validate platform compatibility describes the cause as following:

    Violations are reported if a platform-specific API is used in the context of a different platform or if the platform isn't verified (platform-neutral). Violations are also reported if an API that's not supported for the target platform of the project is used.

    We could try the following method to Suppress violations.

    Please use SupportedOSPlatformGuardAttribute or UnsupportedOSPlatformGuardAttribute in your code.

    Like the following code:

    [SupportedOSPlatform("linux")]  
    public void LinuxOnlyApi() { }  
      
    public void Caller()  
    {  
    #pragma warning disable CA1416  
        LinuxOnlyApi();  
    #pragma warning restore CA1416  
    }  
    

    Hope this could help you.

    Best Regards,
    Jack


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.