visual-studio Visual Studio 错误:“GenerateResource”任务意外失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15034/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Visual Studio Error: The "GenerateResource" task failed unexpectedly
提问by Jon Dewees
When building a VS 2008 solution with 19 projects I sometimes get:
在构建包含 19 个项目的 VS 2008 解决方案时,我有时会得到:
The "GenerateResource" task failed unexpectedly.
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
at System.IO.MemoryStream.set_Capacity(Int32 value)
at System.IO.MemoryStream.EnsureCapacity(Int32 value)
at System.IO.MemoryStream.WriteByte(Byte value)
at System.IO.BinaryWriter.Write(Byte value)
at System.Resources.ResourceWriter.Write7BitEncodedInt(BinaryWriter store, Int32 value)
at System.Resources.ResourceWriter.Generate()
at System.Resources.ResourceWriter.Dispose(Boolean disposing)
at System.Resources.ResourceWriter.Close()
at Microsoft.Build.Tasks.ProcessResourceFiles.WriteResources(IResourceWriter writer)
at Microsoft.Build.Tasks.ProcessResourceFiles.WriteResources(String filename)
at Microsoft.Build.Tasks.ProcessResourceFiles.ProcessFile(String inFile, String outFile)
at Microsoft.Build.Tasks.ProcessResourceFiles.Run(TaskLoggingHelper log, ITaskItem[] assemblyFilesList, ArrayList inputs, ArrayList outputs, Boolean sourcePath, String language, String namespacename, String resourcesNamespace, String filename, String classname, Boolean publicClass)
at Microsoft.Build.Tasks.GenerateResource.Execute()
at Microsoft.Build.BuildEngine.TaskEngine.ExecuteInstantiatedTask(EngineProxy engineProxy, ItemBucket bucket, TaskExecutionMode howToExecuteTask, ITask task, Boolean& taskResult) C:\Windows\Microsoft.NET\Framework\v3.5
Usually happens after VS has been running for about 4 hours; the only way to get VS to compile properly is to close out VS, and start it again.
通常发生在VS已经运行了大约4个小时之后;使 VS 正确编译的唯一方法是关闭 VS,然后重新启动它。
I'm on a machine with 3GB Ram. TaskManager shows the devenv.exe working set to be 578060K, and the entire memory allocation for the machine is 1.78GB. It should have more than enough ram to generate the resources.
我在一台有 3GB 内存的机器上。TaskManager 显示 devenv.exe 工作集为 578060K,整个机器的内存分配为 1.78GB。它应该有足够的内存来生成资源。
采纳答案by Kev
I used to hit this now and again with larger solutions. My tactic was to break the larger solution down into smaller solutions.
我曾经用更大的解决方案一次又一次地解决这个问题。我的策略是将较大的解决方案分解为较小的解决方案。
You could also try:
你也可以试试:
回答by Stu
Try deleting the .suo file and re-opening the solution.
尝试删除 .suo 文件并重新打开解决方案。
回答by Jon Dewees
Sounds like a bug.
听起来像一个错误。
http://www.codeprof.com/dev-archive/66/6-27-664019.shtm
http://www.codeprof.com/dev-archive/66/6-27-664019.shtm
Toward the bottom, someone suggests adding:
在底部,有人建议添加:
<GenerateResourceNeverLockTypeAssemblies>true</GenerateResourceNeverLockTypeAssemblies>
<GenerateResourceNeverLockTypeAssemblies>true</GenerateResourceNeverLockTypeAssemblies>
to your project file. Seems kind of dubious, but worth a shot.
到您的项目文件。看起来有点可疑,但值得一试。
回答by Chris Woodruff
In case someone else is looking in the future...
万一其他人正在寻找未来......
In my case, turned out I had a corrupted resx file.
I had increased my GDI handles and the compile error went away.
就我而言,结果证明我的 resx 文件已损坏。
我增加了 GDI 句柄并且编译错误消失了。
But then when I tried to run the app (with the debugger), We have a login screen that loads the main screen. The login screen called the main screen's "show" event... and the main object never got instantiated - with no error's being raised.
但是当我尝试运行应用程序(使用调试器)时,我们有一个加载主屏幕的登录屏幕。登录屏幕调用主屏幕的“显示”事件......并且主对象从未被实例化 - 没有引发错误。
I reverted the resx file to a previous one and everything is fine now.
我将 resx 文件恢复到以前的文件,现在一切正常。
Visual Studio 2008, VB.Net, Windows 7
Visual Studio 2008、VB.Net、Windows 7
回答by Chris Woodruff
Can you please try adding this property under the first PropertyGroup in your project file?
您能否尝试在项目文件的第一个 PropertyGroup 下添加此属性?
<GenerateResourceNeverLockTypeAssemblies>true</GenerateResourceNeverLockTypeAssemblies>
Let me know if that works.
让我知道这是否有效。
回答by user5686483
I have already passed by this erros sometimes. All you must do is delete all files in the obj path. After that clean and rebuild your solution and it′s done.
有时我已经通过了这个错误。您所要做的就是删除 obj 路径中的所有文件。之后清理并重建您的解决方案,它就完成了。
回答by Sten Bj?rsell
"Clean solution" works fine. Top Menu Build ->Clean , then build, debug and publish all work fine again. Also antivirus like AVAST best disabled to publish and install trouble free. Re-enable after.
“清洁解决方案”工作正常。顶部菜单 Build -> Clean ,然后再次构建、调试和发布所有工作正常。也最好禁用像 AVAST 这样的防病毒软件来发布和安装无故障。后重新启用。
回答by gowtham kondari
TFS likes to mark files as Read Only. delete the contents of obj/x86
TFS 喜欢将文件标记为只读。删除 obj/x86 的内容

