Visual Studio 2010 - ResGen.exe using 25% CPU, very slow Build

Recently I've found that one of our Hotfix Branches was taking a long time to compile (15min or more). This was strange because our main development branch was OK and compiling the same Visual Studio solution in under 3 minutes. The only difference was that in the hotfix branch we still had the project in .NET 2.0.

I saw right away that ResGen.exe (Resource Generator) was executing for a long time and consuming 25% CPU (I guess it would use more CPU if it was multi-threaded :))

The problem you face when you try to solve problems regarding compilation time is that it is very hard to see what is actually taking more time to compile because MSBuild.exe does not provide a complete and easy way to get time metrics.

Although you can call MSBuild in verbose mode  it does not tell you within each project what took longer to compile.

The technique I used to figure out what was going on was to use Process Monitor from Microsoft (made by Mark Russinovich, which I had the opportunity to meet at TechEd Europe last year, and Bryce Cogswell).

So I ran ProcessMonitor and filtered all the results by process name "ResGen.exe" and watched the log while the solution was compiling.

What I found was quite horrific :) ResGen was trying to repeatedly find .NET assemblies in specific versions that do not exist like System.Windows.Forms, Version=4.0.0.0 or System.Drawing, Version=4.0.0.0. I then had to get time differences between each RESX file read operation and so I realized what files were taking longer to generate the resources.

I had RESX files that were taking about 200 seconds to process.

I still do not know why the RESX files from my projects now and then get this malformed references but one thing I know for sure: if I replace the version attribute to 2.0.0.0 the problem goes away and I get the normal compilation times for my solution.

Links:

Print | posted on Wednesday, April 13, 2011 12:11 AM

Feedback

# re: Visual Studio 2010 - ResGen.exe using 25% CPU, very slow Build

left by Sudarshan at 6/28/2011 8:01 AM Gravatar
Hi, I am facign the same issue. In my case the CPU usage for resgen.exe is above 90%. And it takes nearly 200secs to compile just one project. I did not understand your workaround. How did you force the resgen to point to 2.0.0.0?

# re: Visual Studio 2010 - ResGen.exe using 25% CPU, very slow Build

left by Tiago Margalho at 6/28/2011 4:09 PM Gravatar
Hello Sudarshan
In order to solve the problem, you should change all references of "System.Drawing, Version=4.0.0.0" to "System.Drawing, Version=2.0.0.0" in any resource (.resx file). The same applies to other namespaces that do not have a version 4.0.0.0 (like System.Windows.Forms).

When the reference to an assembly is made using the 4.0.0.0 version, the resgen.exe process keeps trying to find that assembly over and over again. Depending on the number of project resources, this leads to a great increase of the overall build time.

# re: Visual Studio 2010 - ResGen.exe using 25% CPU, very slow Build

left by Kvasi at 11/1/2011 2:12 PM Gravatar
Holy fuckin moley, changed to 2.0.0.0 and now resgen takes a couple of seconds. This has been driving me crazy for months.

# re: Visual Studio 2010 - ResGen.exe using 25% CPU, very slow Build

left by Tiago Margalho at 11/1/2011 5:15 PM Gravatar
Kvasi, glad it worked for you!

# re: Visual Studio 2010 - ResGen.exe using 25% CPU, very slow Build

left by teusje at 11/7/2011 9:50 AM Gravatar
Hey,
Thanks for this post. we had a project that was working with .NET 3.5 and as you described it was looking for System.Drawing (4.0).
Via Process Monitor I found also that ResGen had some Buffer Overflows while it was querying information.
(Process Name: ResGen.exe PID: 7800 Operation: QueryAllInformationFile)

We switched to .NET 4.0 and the problem was gone.

We are using DevExpress and I found that this could also be a cause related to the slow builds: http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Studio_.NET_2005/Q_26224259.html

Thanks for posting this!

# re: Visual Studio 2010 - ResGen.exe using 25% CPU, very slow Build

left by Eric Robishaw at 4/20/2012 4:12 PM Gravatar
You are a genius!
Thank you so much... now saving hours!

BTW, for me, I think my Resources got messed with after installing the latest version of Syncfusion. Just in case anyone else is experiencing the same.


# re: Visual Studio 2010 - ResGen.exe using 25% CPU, very slow Build

left by David Hervieux at 7/12/2012 2:29 AM Gravatar
Hi have replaced the resgen.exe by the one in the .NET Framework 2.0 SDK.This has resolved mu issues.
Post A Comment
Title:
Name:
Email:
Comment:
Verification: