簡體   English   中英

C# - Visual Studio中的System.OutOfMemoryException

[英]C# - System.OutOfMemoryException in Visual Studio

我有一個問題,當我在Visual Studio中右鍵單擊我的主窗體並轉到“查看設計器”時出現錯誤。 它說:'拋出了'System.OutOfMemoryException'類型的異常。

堆棧跟蹤:

at System.Reflection.AssemblyName.nGetFileInformation(String s)
at System.Reflection.AssemblyName.GetAssemblyName(String assemblyFile)
at Microsoft.VisualStudio.Design.VSTypeResolutionService.AssemblyEntry.get_AssemblyName()
at Microsoft.VisualStudio.Design.VSTypeResolutionService.AssemblyEntry.get_FullName()
at Microsoft.VisualStudio.Design.VSTypeResolutionService.AssemblyEntry.get_AssemblySpec()
at Microsoft.VisualStudio.Design.VSTypeResolutionService.SearchProjectEntries(String fullName, Boolean correctThread)
at Microsoft.VisualStudio.Design.VSTypeResolutionService.System.ComponentModel.Design.IDesignTimeAssemblyLoader.GetTargetAssemblyPath(AssemblyName runtimeOrTargetAssemblyName, String suggestedAssemblyPath, FrameworkName targetFramework)
at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkUniverse.ResolveAssembly(AssemblyName assemblyName, Assembly runtimeAssembly)
at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkUniverse.GetTypeFromTargetLocation(Type type, Boolean validateBase)
at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkUniverse.GetType(Type type)
at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkUtil.GetCustomAttributes(Type type, Type filter, Boolean inherit, CustomAttributesCache cache)
at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkType.GetCustomAttributes(Type filter, Boolean inherit)
at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkAttributeCollection.GetAttributes(Type type, Type filter)
at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkAttributeCollection.GetAttributes(MemberInfo member, Type filter)
at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkAttributeCollection.get_Attributes()
at System.ComponentModel.AttributeCollection.get_Count()
at Microsoft.VisualStudio.Design.VSDesignSurface.EnsureExtensions(IComponent component)
at Microsoft.VisualStudio.Design.VSDesignSurface.CreateInstance(Type type)
at System.ComponentModel.Design.DesignerHost.System.ComponentModel.Design.IDesignerHost.CreateComponent(Type componentType, String name)
at System.ComponentModel.Design.Serialization.DesignerSerializationManager.CreateInstance(Type type, ICollection arguments, String name, Boolean addToContainer)
at System.ComponentModel.Design.Serialization.DesignerSerializationManager.System.ComponentModel.Design.Serialization.IDesignerSerializationManager.CreateInstance(Type type, ICollection arguments, String name, Boolean addToContainer)
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 System.ComponentModel.Design.Serialization.BasicDesignerLoader.BeginLoad(IDesignerLoaderHost host)  

設計師: http//pastebin.com/hdRB5DAj

今天早上我收到了這個錯誤,但我還是沒有解決。 如果有人能幫助我,我會非常感激!

我只使用了我所有RAM的55%,所以不可能。

正如Hebie博士指出的那樣,令人懷疑的是VS本身是否會拋出OOM異常,而是在你的表單構造函數中。

我以前用過的技術就是打開表單代碼並在構造函數的開頭插入Throw new Exception("Message describing position") 希望現在不是獲得OOM異常,而是獲得剛剛指定的異常。 現在移動此異常,直到您獲得OOM異常。 這將顯示導致OOM的代碼行。

祝好運!

這可能是由多種因素導致的,並且舊版Visual Studio的問題變得更糟(2005年我的經歷特別糟糕)。

當您查看表單的設計者時會發生這種情況,這可能是由於在表單的構造函數或事件處理程序中創建了對象。 當VS將表單加載到設計器中時,它實際上將編譯並創建表單類的實例。 您在表單中創建的任何對象也可能在此時創建。 所有這些都發生在Visual Studio的內存分配中,因此如果要分配大量內存,這可能會妨礙Visual Studio的內存處理。

我建議您對表單的DesignMode屬性執行檢查,並僅在該屬性為false時加載/創建數據類(如Views)的實例。 您還應該准備在整個表單中的事件處理程序中執行此操作,因為這些可以由Visual Studio設計器觸發。

或者,如果你感覺很勇敢,你可以自己調試Visual Studio! 在VS中打開您的項目,然后打開另一個VS實例。 在第二個實例中,使用Debug - > Attach to Process選項並附加到第一個VS實例。 現在打開表單的設計器,看看是否可以識別錯誤發生的位置。 您可能必須在第二個VS實例中的Debug - > Exceptions下打開“break thrown exception”設置,以確保您的調試會話看到所有異常。

祝好運。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM