我有一个最初在VS2010中创建的Windows窗体应用程序。我已经将它迁移到VS2013和VS2015。应用程序编译正常并在VS2015中运行,但如果我尝试打开特定表单,设计器崩溃会发出以下错误:
Error HRESULT E_FAIL has been returned from a call to a COM component.
它没有给出导致错误的代码行,但它确实给出了一个调用堆栈,如下所示:
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at Microsoft.VisualStudio.LanguageServices.Implementation.Utilities.Exceptions.ThrowEFail()
at Microsoft.VisualStudio.LanguageServices.Implementation.CodeModel.CodeTypeRef.LookupTypeSymbol()
at Microsoft.VisualStudio.LanguageServices.Implementation.CodeModel.CodeTypeRef.get_TypeKind()
at EnvDTE.CodeTypeRef.get_TypeKind()
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomParser.GetUrtTypeFromVsType(CodeTypeRef vsType)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomParser.OnTypePopulateMembers(Object sender, EventArgs e)
at System.CodeDom.CodeTypeDeclaration.get_Members()
at Microsoft.VisualStudio.Design.Serialization.CodeDom.MergedCodeDomParser.CodeTypeDeclarationPopulator.OnPopulateMembers(Object sender, EventArgs e)
at System.CodeDom.CodeTypeDeclaration.get_Members()
at System.ComponentModel.Design.Serialization.TypeCodeDomSerializer.Deserialize(IDesignerSerializationManager manager, CodeTypeDeclaration declaration)
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.DeferredLoadHandler.Microsoft.VisualStudio.TextManager.Interop.IVsTextBufferDataEvents.OnLoadCompleted(Int32 fReload)
我很确定这与我在表单上使用自定义控件这一事实有关。自定义控件的代码如下:
Public Class ctlServiceItem
Implements IComponent
Private _SelectedItem As AP_Data.AP_InvoiceService.SelectedItemEnum = AP_Data.AP_InvoiceService.SelectedItemEnum.NA
Public Event SelectedItemChanged As EventHandler
Public Property SelectedItem As AP_Data.AP_InvoiceService.SelectedItemEnum
Get
Return _SelectedItem
End Get
Set(value As AP_Data.AP_InvoiceService.SelectedItemEnum)
_SelectedItem = value
Select Case SelectedItem
Case AP_Data.AP_InvoiceService.SelectedItemEnum.NA
rbNA.Checked = True
Case AP_Data.AP_InvoiceService.SelectedItemEnum.OK
rbOK.Checked = True
Case AP_Data.AP_InvoiceService.SelectedItemEnum.Replaced
rbReplaced.Checked = True
Case AP_Data.AP_InvoiceService.SelectedItemEnum.Required
rbRequired.Checked = True
Case AP_Data.AP_InvoiceService.SelectedItemEnum.Suggested
rbSuggested.Checked = True
End Select
RaiseEvent SelectedItemChanged(Me, EventArgs.Empty)
End Set
End Property
Public Property HeaderText As String
Get
Return GroupBox1.Text
End Get
Set(value As String)
GroupBox1.Text = value
End Set
End Property
Private _Added As Boolean
Public Property Added As Boolean
Get
Return _Added
End Get
Set(value As Boolean)
_Added = value
If _Added Then
rbReplaced.Text = "Added"
Else
rbReplaced.Text = "Replaced"
End If
End Set
End Property
Private Sub rbOK_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rbOK.CheckedChanged
_SelectedItem = AP_Data.AP_InvoiceService.SelectedItemEnum.OK
RaiseEvent SelectedItemChanged(Me, EventArgs.Empty)
End Sub
Private Sub rbSuggested_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rbSuggested.CheckedChanged
_SelectedItem = AP_Data.AP_InvoiceService.SelectedItemEnum.Suggested
RaiseEvent SelectedItemChanged(Me, EventArgs.Empty)
End Sub
Private Sub rbRequired_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rbRequired.CheckedChanged
_SelectedItem = AP_Data.AP_InvoiceService.SelectedItemEnum.Required
RaiseEvent SelectedItemChanged(Me, EventArgs.Empty)
End Sub
Private Sub rbReplaced_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rbReplaced.CheckedChanged
_SelectedItem = AP_Data.AP_InvoiceService.SelectedItemEnum.Replaced
RaiseEvent SelectedItemChanged(Me, EventArgs.Empty)
End Sub
Private Sub rbNA_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rbNA.CheckedChanged
_SelectedItem = AP_Data.AP_InvoiceService.SelectedItemEnum.NA
RaiseEvent SelectedItemChanged(Me, EventArgs.Empty)
End Sub
End Class
另一个控件是
Public Class ctlServiceTireItem
Implements IComponent
Private _SelectedItem As AP_Data.AP_InvoiceService.SelectedItemEnum = AP_Data.AP_InvoiceService.SelectedItemEnum.NA
Public Event SelectedItemChanged As EventHandler
Public Property SelectedItem As AP_Data.AP_InvoiceService.SelectedItemEnum
Get
Return _SelectedItem
End Get
Set(value As AP_Data.AP_InvoiceService.SelectedItemEnum)
_SelectedItem = value
Select Case SelectedItem
Case AP_Data.AP_InvoiceService.SelectedItemEnum.NA
rbNA.Checked = True
Case AP_Data.AP_InvoiceService.SelectedItemEnum.OK
rbOK.Checked = True
Case AP_Data.AP_InvoiceService.SelectedItemEnum.Replaced
rbReplaced.Checked = True
Case AP_Data.AP_InvoiceService.SelectedItemEnum.Required
rbRequired.Checked = True
Case AP_Data.AP_InvoiceService.SelectedItemEnum.Suggested
rbSuggested.Checked = True
End Select
RaiseEvent SelectedItemChanged(Me, EventArgs.Empty)
End Set
End Property
Public Property HeaderText As String
Get
Return GroupBox1.Text
End Get
Set(value As String)
GroupBox1.Text = value
End Set
End Property
Private Sub rbOK_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rbOK.CheckedChanged
_SelectedItem = AP_Data.AP_InvoiceService.SelectedItemEnum.OK
RaiseEvent SelectedItemChanged(Me, EventArgs.Empty)
End Sub
Private Sub rbSuggested_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rbSuggested.CheckedChanged
_SelectedItem = AP_Data.AP_InvoiceService.SelectedItemEnum.Suggested
RaiseEvent SelectedItemChanged(Me, EventArgs.Empty)
End Sub
Private Sub rbRequired_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rbRequired.CheckedChanged
_SelectedItem = AP_Data.AP_InvoiceService.SelectedItemEnum.Required
RaiseEvent SelectedItemChanged(Me, EventArgs.Empty)
End Sub
Private Sub rbReplaced_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rbReplaced.CheckedChanged
_SelectedItem = AP_Data.AP_InvoiceService.SelectedItemEnum.Replaced
RaiseEvent SelectedItemChanged(Me, EventArgs.Empty)
End Sub
Private Sub rbNA_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rbNA.CheckedChanged
_SelectedItem = AP_Data.AP_InvoiceService.SelectedItemEnum.NA
RaiseEvent SelectedItemChanged(Me, EventArgs.Empty)
End Sub
End Class
如果需要,我可以提供表单的设计器代码,但它很庞大。控件在工具箱中显示为Project控件,就像它们应该的那样。它只是在一个版本的VS而不是更新的版本中在设计师中打开是没有意义的。因为它确实在早期版本中工作,所以我真的希望它只是一个模糊的设置或类似的东西。
更新:我尝试创建一个全新的空白表单。我能够将控件拖到新表单上,它们显示正常。当我关闭表单并在设计器中重新打开它时,我得到了与上面相同的错误。问题肯定在于用户控件。
答案 0 :(得分:0)
出于某种原因,我在项目中引用了我自己的项目。我认为这是让早期版本的Visual Studio中的项目识别自己的控件的技巧。看起来这是在VS 2015中修复的。一旦项目没有自己的引用,带有用户控件的表单显示正常。