繁体   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