2014-01-21 58 views
0

我在Visual Studio設計得到這個:Visual Studio設計:可空對象必須有一個價值

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) 

想法?

+2

請顯示您的代碼.. –

+0

整個設計師代碼?這是巨大的! – Denis

+0

關於我應該在Designer代碼中尋找什麼的提示? – Denis

回答

1

發現問題。在.Designer.vb,控制的可爲空的財產被VS2010設計師設置爲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 

最後一行是罪魁禍首 - 別問我是怎麼發現它 - 是純粹的運氣。在這種控制的。價值被定義如下:

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設計在修復了這個問題的所有行。真的希望VS Designer能指向一條線。我發現這一點的唯一方法是查看此文件的TFS歷史記錄並查看最近添加了哪些內容。

+1

一個TypeConverter也可以修復它,如果你需要保持prop屬性...或者而不是Nothing/Nullable return Date.MinDate – Plutonix

+1

+1。 VS設計師有各種各樣的問題。準備好更多。 :) – Neolisk

0

我也有這個問題。我一直在我的應用程序中添加和刪除功能區欄中的很多項目。功能區欄可以包含很多子元素。但是,過去我創建的一些子元素已經從功能區中刪除,但仍然在設計器文件中創建。因此,我確定並刪除了不在我的功能區中的每個元素,並解決了問題。

TLDR:刪除孤立的控件。

相關問題