Thursday, May 3, 2012

ERROR: Resource name XXX cannot be used more than once

ERROR: Resource name XXX cannot be used more than once:
A couple weeks ago I had a client call me up with a perplexing build error. He had an ASP.NET 4 Web Application project open in Visual Studio 2010 that he was working on when, suddenly, the following error cropped up when building:

Resource name ‘xxx.resources’ cannot be used more than once.

There was no line number, just this error message. According to my client, the project built fine minutes before the error started appearing and, in the interim, he had not made any changes that he was aware of: he had not changed any code; had not created any new web pages; had not deleted anything; had not changed the project’s settings.
Unfortunately, we were unable to find much help online. While there are a lot of messageboard posts and blog entries noting this error, most of them were in the context of duplicate key names in resource files – my client’s project was not using resource files.
Anyway, we banged our heads on it for a good hour before we finally chose the nuclear option: start excluding files one by one, building after each one, and see if the error goes away. A ham-fisted approach for sure, but one that would likely identify the culprit.
Eventually we got to the obj folder – why was that part of the project? The obj folder As we started working through the files, I noticed in Solution Explorer that the obj folder holds temporary build files, including .resource files. I presume that when building the project Visual Studio was attempting to create the same files that were already part of the project, and hence the error. In any event, excluding the obj folder from the project did the trick. Once it was omitted the project built without error.
So how did this happen? My client likes having the “Show all files” option turned on in the Solution Explorer. My guess is that he inadvertently right-clicked on the excluded obj folder and clicked the “Include in project” option. Or something, because he said he did not intentionally add the folder to his project. Regardless, its presence caused the build to choke and removing it fixed everything.
Thought I would share this experience here so others would have another possible avenue to check in the event that they receive this build error.
Happy Programming!


ICT4PE&D

No comments:

Post a Comment

Thank's!