Visual Studio Error: The “GenerateResource” task failed unexpectedly

此生再无相见时 提交于 2019-12-07 02:26:48

问题


When building a VS 2008 solution with 19 projects I sometimes get:

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.

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.


回答1:


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:

http://stevenharman.net/blog/archive/2008/04/29/hacking-visual-studio-to-use-more-than-2gigabytes-of-memory.aspx




回答2:


From https://social.msdn.microsoft.com/Forums/vstudio/en-US/5154ef26-ccfe-44d5-a322-6804b61ac774/systemoutofmemoryexception?forum=clr:

Try deleting the .suo file and re-opening the solution.




回答3:


Sounds like a bug.

http://www.codeprof.com/dev-archive/66/6-27-664019.shtm

Toward the bottom, someone suggests adding:

<GenerateResourceNeverLockTypeAssemblies>true</GenerateResourceNeverLockTypeAssemblies>

to your project file. Seems kind of dubious, but worth a shot.




回答4:


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.

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.

Visual Studio 2008, VB.Net, Windows 7




回答5:


Can you please try adding this property under the first PropertyGroup in your project file?

<GenerateResourceNeverLockTypeAssemblies>true</GenerateResourceNeverLockTypeAssemblies>

Let me know if that works.




回答6:


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.




回答7:


"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.




回答8:


TFS likes to mark files as Read Only. delete the contents of obj/x86



来源:https://stackoverflow.com/questions/15034/visual-studio-error-the-generateresource-task-failed-unexpectedly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!