WFDEV001: WParam, LParam, and Message.Result are obsolete

Version introduced: .NET 7

Important

This article is intended for those maintaining Windows Forms. This warning doesn't apply to using Windows Forms.

To reduce the risk of cast and overflow exceptions associated with IntPtr on different platforms, the Windows Forms SDK disallows direct use of Message.WParam, Message.LParam, and Message.Result. Projects that use the DEBUG build of the Windows Forms SDK and that reference WParam, LParam, or Result will fail to compile due to warning WFDEV001.

Workaround

Update your code to use the new internal properties, either WParamInternal, LParamInternal, or ResultInternal depending on the situation.

Suppress a warning

If you must use the obsolete APIs, you can suppress the warning in code or in your project file.

Suppress the warning with either of the following methods:

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

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

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

  • Add the following PropertyGroup to your project file:

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

For more information, see How to suppress code analysis warnings.