Compiler Error WFO5001

'System.Windows.Forms.Application.SetColorMode(System.Windows.Forms.SystemColorMode)' is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.

-or-

'System.Windows.Forms.SystemColorMode' is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.

The color mode feature is currently experimental and subject to change. This error is generated so that you understand the implications of writing code that sets the color mode of the Windows Forms project. The error must be suppressed to continue. For more information about this API, see Dark mode.

Example

The following sample generates WFO5001:

namespace MyExampleProject;

static class Program
{
    [STAThread]
    static void Main()
    {
        ApplicationConfiguration.Initialize();
        Application.SetColorMode(SystemColorMode.Dark);
        Application.Run(new Form1());
    }    
}

To correct this error

Suppress the error and enable access to the API by either of the following methods:

  • Set the severity of the rule in the .editorConfig file.

    [*.{cs,vb}]
    dotnet_diagnostic.WFO5001.severity = none
    

    For more information about editor config files, see Configuration files for code analysis rules.

  • Add the following PropertyGroup to your project file to suppress the error:

    <PropertyGroup>
        <NoWarn>$(NoWarn);WFO5001</NoWarn>
    </PropertyGroup>
    
  • Suppress the error in code with the #pragma warning disable WFO5001 directive:

    namespace MyExampleProject;
    
    static class Program
    {
        [STAThread]
        static void Main()
        {
            ApplicationConfiguration.Initialize();
    #pragma warning disable WFO5001
            Application.SetColorMode(SystemColorMode.Dark);
    #pragma warning restore WFO5001
            Application.Run(new Form1());
        }    
    }