Mitigation: Custom IMessageFilter.PreFilterMessage Implementations
In Windows Forms apps that target versions of the .NET Framework starting with the .NET Framework 4.6.1, a custom IMessageFilter.PreFilterMessage implementation can safely filter messages when the Application.FilterMessage method is called if the IMessageFilter.PreFilterMessage implementation:
Does one or both of the following:
Adds a message filter by calling the AddMessageFilter method.
Removes a message filter by calling the RemoveMessageFilter method. method.
And pumps messages by calling the Application.DoEvents method.
Impact
This change only affects Windows Forms apps that target versions of the .NET Framework starting with the .NET Framework 4.6.1.
For Windows Forms apps that target previous versions of the .NET Framework, such implementations in some cases throw an IndexOutOfRangeException exception when the Application.FilterMessage method is called
Mitigation
If this change is undesirable, apps that target the .NET Framework 4.6.1 or a later version can opt out of it by adding the following configuration setting to the <runtime> section of the app’s configuration file:
<runtime>
<AppContextSwitchOverrides value="Switch.System.Windows.Forms.DontSupportReentrantFilterMessage=true" />
</runtime>
In addition, apps that target previous versions of the .NET Framework but are running under the .NET Framework 4.6.1 or a later version can opt in to this behavior by adding the following configuration setting to the <runtime> section of the app’s configuration file:
<runtime>
<AppContextSwitchOverrides value="Switch.System.Windows.Forms.DontSupportReentrantFilterMessage=false" />
</runtime>