我在Visual Studio Designer中得到了这个:
Nullable object must have a value.
隐秘的堆栈跟踪:
at System.ComponentModel.ReflectPropertyDescriptor.SetValue(Object component, Object value)
at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkPropertyDescriptor.SetValue(Object component, Object value)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializePropertyAssignStatement(IDesignerSerializationManager manager, CodeAssignStatement statement, CodePropertyReferenceExpression propertyReferenceEx, Boolean reportError)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeAssignStatement(IDesignerSerializationManager manager, CodeAssignStatement statement)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager manager, CodeStatement statement)
如何找到问题的想法?
答案 0 :(得分:1)
发现问题。在.Designer.vb中,VS2010 Designer将控件的可空属性设置为Nothing:
'
'cmbInputPostingDate
'
Me.cmbInputPostingDate.AllowUserToType = True
Me.cmbInputPostingDate.DateFormat = "MM/dd/yyyy"
Me.cmbInputPostingDate.Location = New System.Drawing.Point(79, 41)
Me.cmbInputPostingDate.Name = "cmbInputPostingDate"
Me.cmbInputPostingDate.ReadOnly = False
Me.cmbInputPostingDate.SelectionLength = 0
Me.cmbInputPostingDate.SelectionStart = 0
Me.cmbInputPostingDate.Size = New System.Drawing.Size(115, 21)
Me.cmbInputPostingDate.TabIndex = 255
Me.cmbInputPostingDate.TextAlign = System.Windows.Forms.HorizontalAlignment.Left
Me.cmbInputPostingDate.Value = Nothing
最后一行是罪魁祸首 - 不要问我是怎么发现的 - 纯粹是运气。在该控件中,.Value定义如下:
Public Property Value() As Date?
Get
Return mValue
End Get
Set(ByVal val As Date?)
mValue = val
Me.Text = SH.VBFormat(CDate(val), Me.mDateFormat)
End Set
End Property
将以下属性添加到上面的属性:
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
并删除VS2010 Designer提供的所有行修复了此问题。真的希望VS Designer会指向一条线。我发现这一点的唯一方法是查看此文件的TFS历史记录,并查看最近添加了哪些内容。
答案 1 :(得分:0)
我也有这个问题。我一直在添加和删除我的应用程序中的功能区栏中的很多项目。功能区栏可以包含许多子元素。但是,我过去创建的一些子元素已从功能区中删除,但它们仍在设计器文件中创建。所以我确定并删除了我的功能区中不再存在的所有元素,并修复了问题。
TLDR:删除孤立控件。