Obsolete Windows Forms features in .NET 7+
Starting in .NET 7, some Windows Forms APIs are marked as obsolete (or otherwise produce a warning) with custom diagnostic IDs of the format WFDEVXXX
.
If you encounter build warnings or errors due to usage of an obsolete API, follow the specific guidance provided for the diagnostic ID listed in the Reference section. Warnings or errors for these obsoletions can't be suppressed using the standard diagnostic ID (CS0618) for obsolete types or members; use the custom WFDEVXXX
diagnostic ID values instead. For more information, see Suppress warnings.
Reference
The following table provides an index to the WFDEVXXX
obsoletions and warnings in .NET 7+.
Diagnostic ID | Warning or error | Description |
---|---|---|
WFDEV001 | Warning | Casting to/from IntPtr is unsafe. Use WParamInternal , LParamInternal , or ResultInternal instead. |
WFDEV002 | Warning/error | System.Windows.Forms.DomainUpDown.DomainUpDownAccessibleObject is no longer used to provide accessible support for DomainUpDown controls. Use AccessibleObject instead. |
WFDEV003 | Warning | System.Windows.Forms.DomainUpDown.DomainItemAccessibleObject is no longer used to provide accessible support for DomainUpDown items. Use AccessibleObject instead. |
Suppress warnings
It's recommended that you use an available workaround whenever possible. However, if you cannot change your code, you can suppress warnings through a #pragma
directive or a <NoWarn>
project setting. If you must use the obsolete APIs and the WFDEVXXX
diagnostic does not surface as an error, you can suppress the warning in code or in your project file.
To suppress the warnings in code:
// Disable the warning.
#pragma warning disable WFDEV001
// Code that uses obsolete API.
//...
// Re-enable the warning.
#pragma warning restore WFDEV001
To suppress the warnings in a project file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<!-- NoWarn below suppresses WFDEV001 project-wide -->
<NoWarn>$(NoWarn);WFDEV001</NoWarn>
<!-- To suppress multiple warnings, you can use multiple NoWarn elements -->
<NoWarn>$(NoWarn);WFDEV001</NoWarn>
<NoWarn>$(NoWarn);WFDEV003</NoWarn>
<!-- Alternatively, you can suppress multiple warnings by using a semicolon-delimited list -->
<NoWarn>$(NoWarn);WFDEV001;WFDEV003</NoWarn>
</PropertyGroup>
</Project>
Note
Suppressing warnings in this way only disables the obsoletion warnings you specify. It doesn't disable any other warnings, including obsoletion warnings with different diagnostic IDs.
See also
.NET Desktop feedback
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for