I am trying to use a user control component I created and packed in NuGet and I get some errors. When I test the component in a test form within the same solution, by referencing the project, then it works correctly, when I pack it and install the NuGet package in a different solution and try to add it to a Windows Form project then I get this output:
[09:37:40.760285] warn: Could not find field, 'coreNotificationsWidgetControl1'.
[09:37:40.769545] fail: Request failures: DesignerHosts/CreateComponent.
Microsoft.DotNet.DesignTools.Client.DesignToolsServerException: Object reference not set to an instance of an object.
For information on how to troubleshoot the designer refer to the guide at https://aka.ms/winforms/designer/troubleshooting.
[09:37:40.772546] fail: Exception: Microsoft.DotNet.DesignTools.Client.DesignToolsServerException: Object reference not set to an instance of an object.
at Microsoft.DotNet.DesignTools.Client.DesignToolsClient.<SendRequestAsync>d__49`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.Threading.JoinableTask.CompleteOnCurrentThread()
at Microsoft.VisualStudio.Threading.JoinableTask`1.CompleteOnCurrentThread()
at Microsoft.DotNet.DesignTools.Protocol.Endpoints.DesignToolsEndpoints.DesignerHostsImpl.CreateComponent(SessionId sessionId, TypeIdentity type, String name, NameValuePairs defaultValues)
at Microsoft.WinForms.DesignTools.Client.Toolbox.WinFormsToolboxItem.CreateComponentsCore(IDesignerHost host, IDictionary defaultValues)
at System.Drawing.Design.ToolboxItem.CreateComponents(IDesignerHost host, IDictionary defaultValues)
at Microsoft.DotNet.DesignTools.Client.Designers.ComponentProxyDesigner.CreateTool(ToolboxItem tool, Nullable`1 location, Nullable`1 size, ObjectProxy toolboxSnapArgs)
For information on how to troubleshoot the designer refer to the guide at https://aka.ms/winforms/designer/troubleshooting.
[09:37:40.772546] fail: Exception message = Microsoft.DotNet.DesignTools.Client.DesignToolsServerException: Object reference not set to an instance of an object.
at Microsoft.DotNet.DesignTools.Client.DesignToolsClient.<SendRequestAsync>d__49`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.Threading.JoinableTask.CompleteOnCurrentThread()
at Microsoft.VisualStudio.Threading.JoinableTask`1.CompleteOnCurrentThread()
at Microsoft.DotNet.DesignTools.Protocol.Endpoints.DesignToolsEndpoints.DesignerHostsImpl.CreateComponent(SessionId sessionId, TypeIdentity type, String name, NameValuePairs defaultValues)
at Microsoft.WinForms.DesignTools.Client.Toolbox.WinFormsToolboxItem.CreateComponentsCore(IDesignerHost host, IDictionary defaultValues)
at System.Drawing.Design.ToolboxItem.CreateComponents(IDesignerHost host, IDictionary defaultValues)
at Microsoft.DotNet.DesignTools.Client.Designers.ComponentProxyDesigner.CreateTool(ToolboxItem tool, Nullable`1 location, Nullable`1 size, ObjectProxy toolboxSnapArgs)
For information on how to troubleshoot the designer refer to the guide at https://aka.ms/winforms/designer/troubleshooting.
[09:37:46.353328] warn: Could not find field, 'coreNotificationsWidgetControl1'.
The code I have in the CoreNotificationsWidgetControl.cs is
using System;
using System.Windows.Forms;
namespace CoreNotifications_form
{
public partial class CoreNotificationsWidgetControl: UserControl
{
public CoreNotificationsWidgetControl()
{
InitializeComponent();
if (!DesignMode)
{
Load += CoreNotificationsWidgetControl_Load;
}
}
}
}
And in the CoreNotificationsWidgetControl.Designer.cs
using System;
using CoreComm_lib;
using System.Windows.Forms;
namespace CoreNotifications_form
{
partial class CoreNotificationsWidgetControl
{
private CoreLinkManager commManager;
private System.ComponentModel.IContainer components = null;
private TabPage tabPage1;
private TabPage tabPage2;
private Button btnAcknowledge;
private Button btnAcknowledgeAll;
private TabControl tabControlNotifications;
private DataGridView dataCurrentNotificationsGrid;
private DataGridView dataHistoricalNotificationsGrid;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
commManager = new CoreLinkManager();
tabPage1 = new TabPage();
tabPage2 = new TabPage();
btnAcknowledge = new Button();
btnAcknowledgeAll = new Button();
tabControlNotifications = new TabControl();
dataCurrentNotificationsGrid = new DataGridView();
dataHistoricalNotificationsGrid = new DataGridView();
tabControlNotifications.SuspendLayout();
tabPage1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataCurrentNotificationsGrid).BeginInit();
tabPage2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataHistoricalNotificationsGrid).BeginInit();
SuspendLayout();
//
// tabControlNotifications
//
tabControlNotifications.Controls.Add(tabPage1);
tabControlNotifications.Controls.Add(tabPage2);
tabControlNotifications.Location = new System.Drawing.Point(12, 12);
tabControlNotifications.Name = "tabControlNotifications";
tabControlNotifications.SelectedIndex = 0;
tabControlNotifications.Size = new System.Drawing.Size(951, 372);
tabControlNotifications.TabIndex = 0;
//
// tabPage1
//
tabPage1.Controls.Add(dataCurrentNotificationsGrid);
tabPage1.Location = new System.Drawing.Point(4, 29);
tabPage1.Name = "tabPage1";
tabPage1.Padding = new Padding(3);
tabPage1.Size = new System.Drawing.Size(943, 339);
tabPage1.TabIndex = 0;
tabPage1.Text = "Current Notifications";
tabPage1.UseVisualStyleBackColor = true;
//
// dataCurrentNotificationsGrid
//
dataCurrentNotificationsGrid.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataCurrentNotificationsGrid.Location = new System.Drawing.Point(6, 6);
dataCurrentNotificationsGrid.Name = "dataCurrentNotificationsGrid";
dataCurrentNotificationsGrid.RowHeadersWidth = 51;
dataCurrentNotificationsGrid.RowTemplate.Height = 24;
dataCurrentNotificationsGrid.Size = new System.Drawing.Size(931, 327);
dataCurrentNotificationsGrid.TabIndex = 0;
//
// tabPage2
//
tabPage2.Controls.Add(dataHistoricalNotificationsGrid);
tabPage2.Location = new System.Drawing.Point(4, 29);
tabPage2.Name = "tabPage2";
tabPage2.Padding = new Padding(3);
tabPage2.Size = new System.Drawing.Size(943, 339);
tabPage2.TabIndex = 1;
tabPage2.Text = "Historical Notifications";
tabPage2.UseVisualStyleBackColor = true;
//
// dataHistoricalNotificationsGrid
//
dataHistoricalNotificationsGrid.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataHistoricalNotificationsGrid.Location = new System.Drawing.Point(6, 6);
dataHistoricalNotificationsGrid.Name = "dataHistoricalNotificationsGrid";
dataHistoricalNotificationsGrid.RowHeadersWidth = 51;
dataHistoricalNotificationsGrid.RowTemplate.Height = 24;
dataHistoricalNotificationsGrid.Size = new System.Drawing.Size(931, 327);
dataHistoricalNotificationsGrid.TabIndex = 1;
//
// btnAcknowledge
//
btnAcknowledge.Location = new System.Drawing.Point(967, 41);
btnAcknowledge.Name = "btnAcknowledge";
btnAcknowledge.Size = new System.Drawing.Size(137, 42);
btnAcknowledge.TabIndex = 1;
btnAcknowledge.Text = "Acknowledge";
btnAcknowledge.UseVisualStyleBackColor = true;
btnAcknowledge.Click += BtnAcknowledge_Click;
//
// btnAcknowledgeAll
//
btnAcknowledgeAll.Location = new System.Drawing.Point(967, 102);
btnAcknowledgeAll.Name = "btnAcknowledgeAll";
btnAcknowledgeAll.Size = new System.Drawing.Size(137, 42);
btnAcknowledgeAll.TabIndex = 2;
btnAcknowledgeAll.Text = "Acknowledge All";
btnAcknowledgeAll.UseVisualStyleBackColor = true;
btnAcknowledgeAll.Click += BtnAcknowledgeAll_Click;
//
// CoreNotificationsWidgetControl
//
AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
Controls.Add(btnAcknowledge);
Controls.Add(btnAcknowledgeAll);
Controls.Add(tabControlNotifications);
Name = "CoreNotificationsWidgetControl";
Size = new System.Drawing.Size(1114, 390);
Load += CoreNotificationsWidgetControl_Load;
tabControlNotifications.ResumeLayout(false);
tabPage1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataCurrentNotificationsGrid).EndInit();
tabPage2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataHistoricalNotificationsGrid).EndInit();
ResumeLayout(false);
}
#endregion
private void CoreNotificationsWidgetControl_Load(object sender, EventArgs e)
{
if (!DesignMode)
{
InitializeDataGridView();
PopulateDataGridView();
InitializeHistoricalDataGridView();
PopulateHistoricalDataGridView();
}
}
private void InitializeDataGridView()
{
if (dataCurrentNotificationsGrid == null)
return;
dataCurrentNotificationsGrid.Columns.Clear();
// Add columns with specific AutoSizeMode settings
var idColumn = new DataGridViewTextBoxColumn { Name = "Id", HeaderText = "ID", AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells };
var labelColumn = new DataGridViewTextBoxColumn { Name = "Label", HeaderText = "Label", AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells };
var messageColumn = new DataGridViewTextBoxColumn { Name = "Message", HeaderText = "Message", AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill };
var severityColumn = new DataGridViewTextBoxColumn { Name = "Severity", HeaderText = "Severity", AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells };
var statusColumn = new DataGridViewTextBoxColumn { Name = "Status", HeaderText = "Status", AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells };
var sourceColumn = new DataGridViewTextBoxColumn { Name = "Source", HeaderText = "Source", AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells };
var timestampColumn = new DataGridViewTextBoxColumn { Name = "Timestamp", HeaderText = "Timestamp", AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells };
// Add columns to the DataGridView
dataCurrentNotificationsGrid.Columns.AddRange(new DataGridViewColumn[]
{
idColumn,
labelColumn,
messageColumn,
severityColumn,
statusColumn,
sourceColumn,
timestampColumn
});
}
private void InitializeHistoricalDataGridView()
{
if (dataHistoricalNotificationsGrid == null)
return;
dataHistoricalNotificationsGrid.Columns.Clear();
// Add columns with specific AutoSizeMode settings
var idColumn = new DataGridViewTextBoxColumn { Name = "Id", HeaderText = "ID", AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells };
var labelColumn = new DataGridViewTextBoxColumn { Name = "Label", HeaderText = "Label", AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells };
var messageColumn = new DataGridViewTextBoxColumn { Name = "Message", HeaderText = "Message", AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill };
var severityColumn = new DataGridViewTextBoxColumn { Name = "Severity", HeaderText = "Severity", AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells };
var statusColumn = new DataGridViewTextBoxColumn { Name = "Status", HeaderText = "Status", AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells };
var sourceColumn = new DataGridViewTextBoxColumn { Name = "Source", HeaderText = "Source", AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells };
var timestampColumn = new DataGridViewTextBoxColumn { Name = "Timestamp", HeaderText = "Timestamp", AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells };
// Add columns to the DataGridView
dataHistoricalNotificationsGrid.Columns.AddRange(new DataGridViewColumn[]
{
idColumn,
labelColumn,
messageColumn,
severityColumn,
statusColumn,
sourceColumn,
timestampColumn
});
}
public void PopulateDataGridView()
{
if (commManager == null || dataCurrentNotificationsGrid == null)
return;
// Clear existing rows to avoid duplicates
dataCurrentNotificationsGrid.Rows.Clear();
var notifications = commManager.AllNotifications;
foreach (var notification in notifications)
{
dataCurrentNotificationsGrid.Rows.Add(
notification.Id,
notification.Label,
notification.Message,
notification.Severity,
notification.Status,
notification.Source,
notification.FormattedTimestamp
);
}
dataCurrentNotificationsGrid.Sort(dataCurrentNotificationsGrid.Columns["Timestamp"], System.ComponentModel.ListSortDirection.Ascending);
}
public void PopulateHistoricalDataGridView()
{
if (commManager == null || dataHistoricalNotificationsGrid == null)
return;
// Clear existing rows to avoid duplicates
dataHistoricalNotificationsGrid.Rows.Clear();
var historicalNotifications = commManager.HistoricalNotifications;
foreach (var notification in historicalNotifications)
{
dataHistoricalNotificationsGrid.Rows.Add(
notification.Id,
notification.Label,
notification.Message,
notification.Severity,
notification.Status,
notification.Source,
notification.FormattedTimestamp
);
}
}
public void SetCommManager(CoreLinkManager manager)
{
commManager = manager;
}
private void BtnAcknowledge_Click(object sender, EventArgs e)
{
if (dataCurrentNotificationsGrid.SelectedRows.Count > 0)
{
var selectedRow = dataCurrentNotificationsGrid.SelectedRows[0];
var notificationId = selectedRow.Cells["Id"].Value.ToString();
var notificationSource = selectedRow.Cells["Source"].Value.ToString();
var notification = commManager.AllNotifications.Find(n => n.Id == notificationId && n.Source == notificationSource);
if (notification != null)
{
commManager.AcknowledgeNotification(notification);
PopulateDataGridView();
PopulateHistoricalDataGridView();
}
}
}
private void BtnAcknowledgeAll_Click(object sender, EventArgs e)
{
commManager.AcknowledgeAllNotifications();
PopulateDataGridView();
PopulateHistoricalDataGridView();
}
}
}
I am not sure what to check to understand why I am getting this errors or which object reference is not set.
4