VS.NET 2005: “GenerateResource” task failed unexpectedly

Here is another reason why generated code drives me absolutely insane. It’s the mysterious errors that it invariably generates. In this case it is the error:

The “GenerateResource” task failed unexpectedly.

System.NullReferenceException: Object reference not set to an instance of an object.

at Microsoft.Build.Shared.ExceptionHandling.RethrowUnlessFileIO(Exception e)

at Microsoft.Build.Tasks.GenerateResource.NeedSeparateAppDomain()

at Microsoft.Build.Tasks.GenerateResource.Execute()

at Microsoft.Build.BuildEngine.TaskEngine.ExecuteTask(ExecutionMode howToExecuteTask, Hashtable projectItemsAvailableToTask, BuildPropertyGroup projectPropertiesAvailableToTask, Boolean& taskClassWasFound)

 

For no appraent reason I started to get this type of error in three of my SmartDevice projects in the same solution. Well the equally miraculous solution from http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=491745&SiteID=1 is to put the command:

 

 

<GenerateResourceNeverLockTypeAssemblies>true</GenerateResourceNeverLockTypeAssemblies>

 

in the project file in the PropertyGroup. And magically everything compiles and runs.

It’s things like this that really make me wonder if drag-and-drop designer tools have really helped us to write better code, or just allow us to get in to trouble in new and exciting ways.