Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix 2091 Remove deprecated controls #2157

Conversation

RussKie
Copy link
Member

@RussKie RussKie commented Oct 23, 2019

Fixes #2091

Proposed changes

  • Remove the following API because they have been obsolete since .NET 2.0:
    • Menu
    • MainMenu
    • ContextMenu
    • MenuItem
    • IMenuEditorService
    • ToolBar
    • ToolBarAppearance
    • ToolBarButton
    • ToolBarButtonClickEventArgs
    • ToolBarButtonClickEventHandler
    • ToolBarButtonStyle
    • ToolBarTextAlign
    • DataGrid
    • DataGridAddNewRow
    • DataGridBoolColumn
    • DataGridCaption
    • DataGridCell
    • DataGridColumnCollection
    • DataGridColumnStyle
    • DataGridDefaultColumnWidthTypeConverter
    • DataGridLineStyle
    • DataGridParentRows
    • DataGridParentRowsLabel
    • DataGridRelationshipRow
    • DataGridRow
    • DataGridState
    • DataGridTableCollection
    • DataGridTableStyle
    • DataGridTextBox
    • DataGridTextBoxColumn
    • DataGridToolTip
    • GridTablesFactory
    • IDataGridEditingService
  • Remove the following members in AxHost type:
    • ContextMenu ContextMenu { get; set; }
    • event EventHandler ContextMenuChanged
  • Remove the following members in Control type:
    • ContextMenu ContextMenu { get; set; }
    • event EventHandler ContextMenuChanged
    • void OnContextMenuChanged(EventArgs e)
  • Remove the following members in Form type:
    • MainMenu Menu { get; set; }
    • MainMenu MergedMenu { get; }
    • void Control.OnContextMenuChanged(EventArgs e)
  • Remove the following members in NotifyIcon type:
    • ContextMenu ContextMenu { get; set; }
  • Remove the following members in PrintPreviewDialog type:
    • MainMenu Menu { get; set; }
    • ContextMenu ContextMenu { get; set; }
    • event EventHandler ContextMenuChanged
  • Remove the following members in ToolStripDropDown type:
    • ContextMenu ContextMenu { get; set; }
    • event EventHandler ContextMenuChanged
  • Remove the following members in TreeNode type:
    • ContextMenu ContextMenu { get; set; }
  • Remove the following members in UpDownBase type:
    • ContextMenu ContextMenu { get; set; }

Customer Impact

  • Removed controls no longer available to customers and will cause builds to break
  • Customers will need to replace the removed controls with available alternatives.

Regression?

  • No

Risk

  • Medium, the controls in questions have been deprecated in .NET 2.0 era, however there is a recorded use of those.

Testing

Tested by the CTI team

Microsoft Reviewers: Open in CodeFlow

@RussKie RussKie added 📫 waiting-approval Servicing-consider .NET Shiproom label indicating a PR seeks to enter into a branch under Tell-Mode criteria labels Oct 23, 2019
@RussKie RussKie requested a review from a team as a code owner October 23, 2019 06:49
@RussKie RussKie self-assigned this Oct 23, 2019
@mikedn
Copy link

mikedn commented Oct 23, 2019

It seems strange that controls such as Menu and ContextMenu are marked as deprecated. These are just wrappers over OS provided functionality and I haven't heard of that being deprecated.

@codecov
Copy link

codecov bot commented Oct 23, 2019

Codecov Report

Merging #2157 into release/3.1 will decrease coverage by 0.84281%.
The diff coverage is 13.95349%.

@@                 Coverage Diff                 @@
##           release/3.1     #2157         +/-   ##
===================================================
- Coverage     26.41782%   25.575%   -0.84282%     
===================================================
  Files              818       793         -25     
  Lines           268811    252958      -15853     
  Branches         38145     35956       -2189     
===================================================
- Hits             71014     64694       -6320     
+ Misses          192719    183539       -9180     
+ Partials          5078      4725        -353
Flag Coverage Δ
#Debug 25.575% <13.95349%> (-0.84282%) ⬇️
#production 25.575% <13.95349%> (-0.84282%) ⬇️
#test 100% <ø> (ø) ⬆️

@mikedn
Copy link

mikedn commented Oct 23, 2019

I don't see how that documentation piece implies deprecation.

@weltkante
Copy link
Contributor

weltkante commented Oct 23, 2019

@mikedn the documentation says the classes/properties couldn't be removed for backwards compatibility and you should use the replacement instead for any new code, sounds pretty much like deprecation to me even if it isn't spelled out. Its not said the underlying win32 API is deprecated, but having the same concept mapped twice into WinForms is unnecessary to say the least. WinForms already started this deprecation in other PRs, this is just continuing it. If you have problems with it and reasons to use those classes in your application its probably a good idea to open a separate issue to discuss it, as some PRs have already passed I think.

For what it matters the corresponding properties to set e.g. ContextMenu have been removed from designers for a while, it is just consequential to also hide the classes

@mikedn
Copy link

mikedn commented Oct 23, 2019

the documentation says the classes/properties couldn't be removed for backwards compatibility and you should use the replacement instead for any new code, sounds pretty much like deprecation to me even if it isn't spelled out

The documentation does not say "you should use the replacement". The documentation says "retained for both backward compatibility and future use if you choose".

If you have problems with it and reasons to use those classes in your application its probably a good idea to open a separate issue to discuss it, as some PRs have already passed I think.

Thanks but considering RussKie's teleported documentation paragraph without any other comment and your claim that the documentation says something that it actually doesn't I'm probably wasting my time here.

@weltkante
Copy link
Contributor

weltkante commented Oct 23, 2019

@mikedn language lawyering is probably wasting time, yes. If something has been "retained for backwards compatibility" it indicates it was considered to be removed/replaced. Deprecation is not a formal process (even if it sometimes would be nice to have one) and documentation isn't specification (so arguing as such is also wasting time). I'm just explaining, if you don't care or are aware thats ok, I won't continue the discussion.

"retained for [...] future use if you choose"

Well, that should probably be updated in the .NET Core documentation then, assuming they are planning on actually removing the API in later versions and not just keep hiding it from view.

@merriemcgaw merriemcgaw added Ask-Mode and removed 📫 waiting-approval Servicing-consider .NET Shiproom label indicating a PR seeks to enter into a branch under Tell-Mode criteria labels Oct 23, 2019
@merriemcgaw
Copy link
Member

In .NET Framework we were bound to never remove any types because of the backwards compatibility reasons. .NET Core, being a SxS framework allows us more flexibility in this area. We've created, and the bulk of our customers use, the replacements of MenuStrip and DataGridView classes. As we modernize WinForms on Core we may be removing classes for which there are better alternatives. If a customer really wants to use the Menu, DataGrid and ContextMenu they are able to keep their app on the current version .NET Core (3.0) and use the classes. If they want to use other improvements in the stack we encourage them to look at the replacement classes.

@leecow leecow added Servicing-approved .NET Shiproom approved the PR for merge and removed Ask-Mode labels Oct 29, 2019
@RussKie RussKie added the 🚫 * NO-MERGE * The PR is not ready for merge yet (see discussion for detailed reasons) label Oct 30, 2019
@RussKie RussKie changed the title Fix 2091 Mark deprecated controls as non-browsable WIP: fix 2091 Mark deprecated controls as non-browsable Oct 30, 2019
@RussKie RussKie force-pushed the fix_2091_mark_deprecated_controls_as_nonbrowsable branch 2 times, most recently from 1291188 to 527587c Compare October 30, 2019 05:44
@RussKie RussKie changed the title WIP: fix 2091 Mark deprecated controls as non-browsable WIP: fix 2091 Mark deprecated controls as obsolete Oct 30, 2019
if (ContextMenu != null)
{
CaptureInternal = false;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a bug, originally CaptureInternal = true if ContextMenu != null || ContextMenuStrip != null, however it was reverted only in case of ContextMenu != null...

Copy link
Contributor

@weltkante weltkante Nov 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also have been a workaround for HMENU specific behavior, maybe HWND based menus didn't need to reset the capture, the events and call chains would have been entirely different. Without comments why it was done the way it is thats really hard to tell.

@@ -4157,49 +4151,15 @@ public HRESULT GetDragDropEffect(BOOL fDrag, int grfKeyState, ref int pdwEffect)
public HRESULT GetContextMenu(short seltype, IntPtr lpoleobj, ref Richedit.CHARRANGE lpchrg, out IntPtr hmenu)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❗️ I'm really unsure about this method 😕

Copy link
Contributor

@weltkante weltkante Oct 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think ContextMenuStrip.Handle is a HMENU, is it? (Probably HWND) I don't know how this GetContextMenu method is used but if its for interop with win32 richedit you can't just rip out and replace their usage of HMENU. In fact, if you need HMENU for interop with a native controls menu you can't get rid of the old class at all (well you can replace it with something internal I guess)

Copy link
Contributor

@weltkante weltkante Nov 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to confirm, I've checked base classes (see my other comment) and my suspicion is correct and you introduced a bug here by using ContextMenuStrip.Handle (HWND) in place of ContextMenu.Handle (HMENU)

Copy link
Contributor

@weltkante weltkante Nov 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you did the same update here as with the other HMENU Handle access, I agree removing the code block for now until some regression can be identified (if there is any) is definitely better than leaving broken code in place.

For what its worth context menus appear to work without having this code block in place, so if it triggers at all it probably needs very special conditions and doesn't affect the general usecase.

@weltkante
Copy link
Contributor

weltkante commented Oct 30, 2019

Marking things as [Obsolete(error: true)] means you can't use them anymore, right? Why retain implementation at all then? From what I can see in the PR you are ripping out random implementation details, that doesn't seem right to me. Either you retain implementation and the ability to use the classes, or you remove it cleanly everywhere.

IMHO the title of the PR is misleading, you are not just marking deprecated controls as obsolete, you are already removing the functionality.

This should definitely NOT go into 3.1, thats something for a major version change. Sorry for not noticing this initially [edit] right, I see the title was changed and the [Obsolete(error: true)] was added later, that explains my confusion. I think this PR is going too far now for a 3.1 PR.

@RussKie
Copy link
Member Author

RussKie commented Oct 30, 2019

We have new directions every day 😁
We are planning to rip all these types out. So everything about this PR will change.

@RussKie RussKie removed the Servicing-approved .NET Shiproom approved the PR for merge label Oct 30, 2019
@RussKie RussKie changed the title WIP: fix 2091 Mark deprecated controls as obsolete WIP: fix 2091 Remove deprecated controls Oct 30, 2019
@RussKie RussKie force-pushed the fix_2091_mark_deprecated_controls_as_nonbrowsable branch 2 times, most recently from fe34344 to c4c39bf Compare October 31, 2019 05:52
@weltkante
Copy link
Contributor

Ok, just make sure you get the interop right, I'm not an expert on that part of the WinForms implementation but I think the replacement classes are a WinForms-only reimplementation (not a wrapper around win32 anymore) while the classes to be removed were interoperable with the win32 HMENU API. That means the replacement will be incompatible with any win32 interop (e.g. richedit came up above, ActiveX hosting and various OLE interfaces are other candidates which may interop over HMENU)

@RussKie RussKie force-pushed the fix_2091_mark_deprecated_controls_as_nonbrowsable branch from ef75d09 to c25937a Compare November 7, 2019 01:42
@RussKie RussKie added 📖 documentation: breaking A change in behavior that could be breaking for applications. Needs to be documented. and removed 🚫 * NO-MERGE * The PR is not ready for merge yet (see discussion for detailed reasons) labels Nov 7, 2019
@RussKie RussKie added this to the 3.1 milestone Nov 7, 2019
@RussKie RussKie merged commit 1317264 into dotnet:release/3.1 Nov 7, 2019
@RussKie RussKie deleted the fix_2091_mark_deprecated_controls_as_nonbrowsable branch November 7, 2019 23:10
@bigworld12
Copy link

i have a concern though, winforms (unlike wpf) is heavily reliant on the visual designer, i.e. any modifications to the design will have to go through the visual designer, how do you plan on simplifying that process to replace old deprecated controls with new ones?

@RussKie
Copy link
Member Author

RussKie commented Nov 8, 2019

how do you plan on simplifying that process to replace old deprecated controls with new ones?

It is not possible to replace controls via the Designer.
If you're porting a project that contains any of the above controls to .NET Core 3.1 you will need to replace them manually. Everything else should just work.

@RussKie
Copy link
Member Author

RussKie commented Nov 12, 2019

Docs: dotnet/docs#15813

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
📖 documentation: breaking A change in behavior that could be breaking for applications. Needs to be documented. Servicing-approved .NET Shiproom approved the PR for merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants