2013-05-10 58 views
7

由於將我們的公司內部winforms應用程序從VS2008轉換爲VS2012項目,我在使用winforms設計器時遇到了問題。收藏已修改;枚舉操作可能無法在VS WinForms Designer中執行

有時候設計師陷入錯誤狀態給出以下錯誤消息:

「集合被修改;枚舉操作可能不會執行。」與調用堆棧說:

Instances of this error (1) 

1. Hide Call Stack 

at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) 
at System.Collections.Generic.List`1.Enumerator.MoveNextRare() 
at System.Collections.Generic.List`1.Enumerator.MoveNext() 
at Microsoft.VisualStudio.Design.VSTypeResolutionService.AssemblySpecFound(List`1 assemblies, String assemblyFullName) 
at Microsoft.VisualStudio.Design.VSTypeResolutionService.AddDependencies(Assembly a, String fileName) 
at Microsoft.VisualStudio.Design.VSTypeResolutionService.AssemblyEntry.get_Assembly() 
at Microsoft.VisualStudio.Design.VSTypeResolutionService.SearchByShortName(String partialName, String fullName, AssemblyEntry[] entries, Assembly& assembly) 
at Microsoft.VisualStudio.Design.VSTypeResolutionService.SearchNormalEntries(AssemblyName assemblyName, String typeName, Boolean ignoreTypeCase, Assembly& assembly, Boolean fastSearch) 
at 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.GetAssembly(AssemblyName name, Boolean throwOnError) 
at Microsoft.VisualStudio.Design.VSTypeResolutionService.System.ComponentModel.Design.ITypeResolutionService.GetAssembly(AssemblyName name) 
at Microsoft.VisualStudio.Design.VSDynamicTypeService.OnAssemblyResolve(Object sender, ResolveEventArgs e) 
at System.AppDomain.OnAssemblyResolveEvent(RuntimeAssembly assembly, String assemblyFullName) 

似乎設計師正試圖改變引用的程序集的列表,可能是因爲一些無效的程序集。 在試圖解決這個問題時,我發現改變Project-> Properties-> Security下的「啓用ClickOnce安全性」選項可以讓設計人員恢復工作。但如果該選項打開,我得到設計師的錯誤關閉和重建所有可以不時解決問題和VICE VERSA !!!! ...這就是爲什麼我現在有點迷路了。

+0

也許你應該先嚐試升級到2010年。 :/ – 2013-05-10 08:35:52

+0

在引發異常之前,集合已被修改*。所以這個callstack根本不會幫你。完全不清楚您的表單可能會導致此異常。 – 2013-05-10 10:14:58

回答

1

它似乎是一個常見的Visual Studio 2012錯誤。

下面是官方的郵件,我從微軟

Greetings from Microsoft Connect!

This notification was generated for feedback item: VS2012 WinForms Designer doesn't work anymore -Error: Collection was modified; enumeration operation may not execute.which you submitted at theMicrosoft Connect site.

Thank you for your feedback. This bug is a duplicate of the one reported here: http://connect.microsoft.com/VisualStudio/feedback/details/781193/form-designer-error-collection-was-modified-enumeration-operation-may-not-executethere Please monitor that issue (781193) for further updates. There are no workarounds available, but we are fixing this issue in the next release of Visual Studio.

+0

我剛剛安裝了VS2012更新3.問題仍然存在。看起來像修補程序的「下一個版本」將是VS2013。 – 2013-07-05 09:38:25

4

有我有同樣的問題,這讓我抓狂了一整天。原因(當然除了Visual Studio錯誤)是因爲我的項目缺少一個程序集引用。確切地說,它引用了兩個程序集A和B,其中A本身也引用了B - 但是與我使用的版本不同。我應該引用與引用的B相同的版本。

它歸結爲:我的程序集引用不完全正確。它們足夠讓代碼編譯和運行得很好,但是對於WinForms設計器來說崩潰是不夠的。

爲了找到問題,我開始了第二個VS實例,並將其調試器附加到第一個加載了我的解決方案的調試器(Debug | Attach to Process)。然後在Debug |中例外情況,我激活了公共語言運行時例外。現在,在我的第一個VS實例中,我雙擊表單打開它。

我在一行中有多個異常,其中大部分與我的代碼無關。但其中一個是FileLoadException聲明:「無法加載文件或程序集'XXX,版本= 3.7.0.25089,...」所以我添加了對程序集正確版本的引用。 (正確的話,我的意思是指最後一位數字 - WinForms設計師在組裝版本時非常迂腐。)接下來我知道,表單打開就像一個魅力!

+0

這聽起來像是一個很好的解決方法。當將我們的項目從VS2008遷移到VS2012時,我們也從小型項目中取得了一些小結,最終以一個版本地獄結束。我會嘗試你的建議,並在我們引用的DLL中尋找錯誤的版本號 – LazyGeek 2013-07-06 08:49:01

相關問題