Compiler Warning WFDEV005

Version introduced: .NET 10 Preview 1

Clipboard.GetData(string) is obsolete. Use Clipboard.TryGetData<T> methods instead.

-or-

DataObject.GetData methods are obsolete. Use the corresponding DataObject.TryGetData<T> instead.

-or-

ClipboardProxy.GetData(As String) method is obsolete. Use ClipboardProxy.TryGetData(Of T)(As String, As T) instead.

Using Clipboard.GetData(String), DataObject.GetData, or ClipboardProxy.GetData(String), generates warning WFDEV005 at compile time. These methods rely on BinaryFormatter, which is deprecated for security reasons. For more information, see Windows Forms migration guide for BinaryFormatter.

Workaround

Replace references to these methods with ones that don't use BinaryFormatter.

Original method Replacement method
Clipboard.GetData(String) Clipboard.TryGetData
DataObject.GetData DataObject.TryGetData
ClipboardProxy.GetData(String) ClipboardProxy.TryGetData

Suppress a warning

Suppress the warning with either of the following methods:

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

    [*.{cs,vb}]
    dotnet_diagnostic.WFDEV005.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);WFDEV005</NoWarn>
    </PropertyGroup>
    
  • Suppress in code with the #pragma warning disable WFDEV005 directive.

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