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

查看:41
本文介绍了C# - Visual Studio 中的 System.OutOfMemoryException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个问题,当我在 Visual Studio 中右键单击主窗体并转到视图设计器"时,出现错误.它说:'抛出了'System.OutOfMemoryException'类型的异常.'

I have a problem, when I right click my main form in Visual Studio and go to 'View Designer' I get an error. It says: 'Exception of type 'System.OutOfMemoryException' was thrown.'

堆栈跟踪:

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

今天早上我遇到了这个错误,但我仍然没有解决它.如果有人能帮助我,我将不胜感激!

I got this error this morning, but I still haven't resolved it. If anyone could help me I would really appreciate it!

我只使用了大约 55% 的 RAM,所以不可能.

I'm only using ~55% of all my RAM, so that can't be it.

推荐答案

导致这种情况的原因有很多,而且使用旧版本的 Visual Studio 时问题会变得更糟(在我的体验中,2005 尤其糟糕).

There are multiple things that this can be caused by, and the problem gets worse with older version of Visual Studio (2005 was particularly bad in my experience).

当您查看表单的设计器时会发生这种情况,这可能是由于在表单的构造函数或事件处理程序中创建了对象.当 VS 将您的表单加载到设计器中时,它实际上会编译并创建表单类的实例.您在表单中创建的任何对象也可能会在此时创建.所有这些都发生在 Visual Studio 的内存分配中,因此如果您要分配大量内存,这可能会妨碍 Visual Studio 的内存处理.

As this is happening when you view the designer of a form, there is a chance that this is due to objects being created in your form's constructor or event handlers. When VS loads your form into the designer it will actually compile and create an instance of the form class. Any objects you create within the form are likely to get created at this time as well. All this happens within Visual Studio's memory allocation so if you are allocating a large amount of memory this can hinder Visual Studio's memory handling.

我建议您检查表单的 DesignMode 属性,并且仅在该属性为 false 时加载/创建数据类(如视图)的实例.您还应该准备好在整个表单的事件处理程序中执行此操作,因为它们可以由 Visual Studio 设计器触发.

I would suggest you perform a check on the DesignMode property of the form and only load/create instances of data classes (like Views) when that property is false. You should also be prepared to do this in event handlers throughout the form as these can be fired by the Visual Studio designer.

或者,如果您感到勇敢,实际上可以自己调试 Visual Studio!在 VS 中打开您的项目,然后打开另一个 VS 实例.在第二个实例中,使用 Debug -> Attach to Process 选项并附加到第一个 VS 实例.现在打开表单的设计器,看看是否可以确定错误发生的位置.您可能需要在第二个 VS 实例中的 Debug -> Exceptions 下打开中断抛出异常"设置,以确保您的调试会话看到所有异常.

Alternatively, if you're feeling brave, you can actually debug Visual Studio with itself! Open your project in VS and then open another instance of VS. In the second instance use the Debug -> Attach to Process option and attach to the first VS instance. Now open the designer for your form and see if you can identify where the error occurs. You may have to switch on the 'break on thrown exceptions' settings under Debug -> Exceptions in the second VS instance to ensure your debugging session sees all exceptions.

祝你好运.

这篇关于C# - Visual Studio 中的 System.OutOfMemoryException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆