@@ -53,6 +53,8 @@ internal partial class CommandSet : IDisposable
53
53
private StatusCommandUI _statusCommandUI ; // Used to update the statusBar Information.
54
54
private readonly IUIService ? _uiService ;
55
55
56
+ private ICollection ? _toBeCopiedComponents ;
57
+
56
58
/// <summary>
57
59
/// Creates a new CommandSet object. This object implements the set
58
60
/// of commands that the UI.Win32 form designer offers.
@@ -422,6 +424,7 @@ internal static bool ExecuteSafely(Action action, bool throwOnException)
422
424
423
425
// This function will return true if call to func is successful, false otherwise
424
426
// Output of call to func is available in result out parameter
427
+ [ SuppressMessage ( "Style" , "IDE0051:Remove unused private members" , Justification = "retain this unused method" ) ]
425
428
private static bool ExecuteSafely < T > ( Func < T > func , bool throwOnException , [ MaybeNullWhen ( false ) ] out T result )
426
429
{
427
430
try
@@ -1383,7 +1386,6 @@ protected void OnMenuCenterSelection(object? sender, EventArgs e)
1383
1386
}
1384
1387
}
1385
1388
1386
- private ICollection _toBeCopiedComponents ;
1387
1389
/// <summary>
1388
1390
/// Called when the copy menu item is selected.
1389
1391
/// </summary>
@@ -1835,9 +1837,9 @@ protected void OnMenuPaste(object? sender, EventArgs e)
1835
1837
1836
1838
using DesignerTransaction trans = host . CreateTransaction ( SR . CommandSetPaste ) ;
1837
1839
1838
- components = DesignerUtils . CopyDragObjects ( new ReadOnlyCollection < IComponent > ( [ .. _toBeCopiedComponents . Cast < IComponent > ( ) ] ) , GetService < IDesignerHost > ( ) ) ;
1840
+ components = DesignerUtils . CopyDragObjects ( new ReadOnlyCollection < IComponent > ( [ .. _toBeCopiedComponents . Cast < IComponent > ( ) ] ) , GetService < IDesignerHost > ( ) ! ) ;
1839
1841
1840
- if ( _toBeCopiedComponents . Count == components . Count )
1842
+ if ( components is not null && _toBeCopiedComponents . Count == components . Count )
1841
1843
{
1842
1844
int i = 0 ;
1843
1845
foreach ( IComponent component in _toBeCopiedComponents )
0 commit comments