2010-06-14 22 views
0

我有一個Windows窗體,我正在添加一些新功能。該表格大約有100個控件。我在查看「屬性」下拉列表時發現,在窗體中有幾十個控件沒有用處,並且在屬性窗口中選中它們時,窗體上不可見。Visual Studio 2005 Windows窗體設計器 - 「對象引用未設置爲對象的實例」

我找不到一個簡單的解決方案,通過搜索刪除這些「隱形」控件,所以我決定手動打開.designer文件,並小心地將它們從代碼中刪除。這似乎工作正常,直到我刪除了最後一個「不明」的控件,現在我在設計視圖中打開表單時出現上述錯誤。

該項目仍然編譯和運行良好,它只是在設計視圖中我得到這個錯誤。不幸的是,這使得在未來更新這種形式非常困難。以下是完整的錯誤消息。

加載設計器時遇到一個或多個錯誤。錯誤列在下面。有些錯誤可以通過重建項目來解決,而其他錯誤則可能需要更改代碼。

未將對象引用設置爲對象的實例。 隱藏

在System.Reflection.Assembly._nLoad(的AssemblyName文件名,字符串的代碼庫,證據assemblySecurity,裝配locationHint,StackCrawlMark & stackMark,布爾throwOnFileNotFound,布爾forIntrospection) 在System.Reflection.Assembly.nLoad(的AssemblyName文件名,串的代碼庫,證據assemblySecurity,裝配locationHint,StackCrawlMark & stackMark,布爾throwOnFileNotFound,布爾forIntrospection) 在System.Reflection.Assembly.InternalLoad(的AssemblyName assemblyRef,證據assemblySecurity,StackCrawlMark & stackMark,布爾forIntrospection) 在System.Reflection.Assembly。 InternalLoad(String assemblyString,Evidence assembl ySecurity,StackCrawlMark & stackMark,布爾forIntrospection) 在System.Reflection.Assembly.Load(字符串assemblyString) 在Microsoft.VisualStudio.Design.VSTypeResolutionService.AssemblyEntry.get_Assembly() 在Microsoft.VisualStudio.Design.VSTypeResolutionService.AssemblyEntry.Search (全名的字符串,字符串的typeName,布爾ignoreTypeCase,裝配&組件,字符串描述) 在Microsoft.VisualStudio.Design.VSTypeResolutionService.SearchNormalEntries(的AssemblyName的AssemblyName,字符串的typeName,布爾ignoreTypeCase,裝配&組件,布爾FASTSEARCH) 在Microsoft.VisualStudio .Design.VSTypeResolutionService.SearchEntries(AssemblyName assemblyName,String typeName,Boolean ignoreCase,Assembly & assembly,ReferenceType refType) at Microsoft.VisualStudio.Design.VSTypeResolutionService.SearchEntries(AssemblyName assemblyName,String typeName,Boolean ignoreTypeCase,Assembly & assembly) at Microsoft.VisualStudio.Design.VSTypeResolutionService.System.ComponentModel.Design.ITypeResolutionService.GetType (String typeName,Boolean throwOnError,Boolean ignoreCase) at Microsoft.VisualStudio.Design.VSTypeResolutionService.System.ComponentModel.Design.ITypeResolutionService.GetType(String name,Boolean throwOnError) at Microsoft.VisualStudio.Design.Serialization.CodeDom.HandlesClauseManager。 GetReferencedComponentType(String componentName,CodeTypeDeclaration codeTypeDecl,ITypeResolutionService loader,IDictionary & cache) at Microsoft.VisualStudio.Design.Serializati on.CodeDom.HandlesClauseManager.ParseHandlesClauses(CodeTypeDeclaration codeTypeDecl,Boolean updateCache) at Microsoft。VisualStudio.Design.Serialization.CodeDom.VSCodeDomParser.OnMethodPopulateStatements(對象發件人,EventArgs的) 在System.CodeDom.CodeMemberMethod.get_Statements() 在System.ComponentModel.Design.Serialization.TypeCodeDomSerializer.Deserialize(IDesignerSerializationManager經理,CodeTypeDeclaration聲明) 在System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager經理) 在Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager) 在System.ComponentModel.Design.Serialization.BasicDesignerLoader.BeginLoad(IDesignerLoaderHost主機)

不幸的是,無論是錯誤消息還是在Visual設計器中打開文件都不能指示文件中哪條線路可能失敗 - 只是這個非常模糊的錯誤消息。

我會發布導致錯誤的代碼在這裏,但它佔用了大約100,000個字符,這裏的限制是30,000。

回答

2

我備份了我的設計器代碼,然後從SourceSafe回滾。然後我關閉了表單的設計視圖,關閉了Visual Studio,重新打開了Visual Studio,並粘貼了我的設計器代碼。完成後,我可以雙擊表單查看它。

我仍然不確定是什麼原因導致了錯誤,但是按照上面的方法修復了它。奇怪的。

+0

Winforms設計器被稱爲隨機產生一些未知的錯誤。幸運的是,它並不經常發生。 – l46kok 2013-09-17 04:48:46

相關問題