views:

67

answers:

3

Lately with Visual Studio 2010 Ultimate, C#, in Win7 64bit, I get the error below when I compile any project. The workaround is to add <TrackFileAccess>false</TrackFileAccess> to the project file. If I am not mistaken this would disable incremental builds so I want to stay away from this workaround.

Anyone knows what the permanent reliable fix is? I did reinstall .NET Framework 4 and VS 2010. I don't have beta or prior versions of 4.0 framework folders.

Error   1   The "GenerateResource" task failed unexpectedly.
System.TypeInitializationException: The type initializer for 'Microsoft.Build.Utilities.FileTracker' threw an exception. ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Build.Utilities.FileTracker..cctor()
   --- End of inner exception stack trace ---
   at Microsoft.Build.Utilities.FileTracker.ForceOutOfProcTracking(ExecutableType toolType, String dllName, String cancelEventName)
   at Microsoft.Build.Tasks.GenerateResource.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext 
A: 

This workaround is from the MS forums:

Edit your project file and add this to the first PropertyGroup:

<GenerateResourceNeverLockTypeAssemblies>true</GenerateResourceNeverLockTypeAssemblies>
Mitch Wheat
It didn't help. The issue mentioned in that post seems to be a different one.
Tony_Henrich
+1  A: 

I found the solution for my environment by reflecting Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Build.Utilities.v4.0.dll

My TEMP/TMP environment variable was pointing to a ram drive root folder (T:\) without any further directory nesting! The line s_tempPath = Path.GetDirectoryName(Path.GetTempPath()); in the static ctor of Microsoft.Build.Utilities.FileTracker resulted in null, which caused the exception as mentioned by you.

Now my TEMP/TMP environment variable is pointing to T:\TEMP and everything is working fine.

Harald
Excellent sleuthing! I had this same issue. I had the DLL open in Reflector and was starting to go over the FileTracker class as well, when I saw your post.
JustinB
A: 

You sir, are a genius. Had the system thrown an error like "Null Error in GetTempPath", I might have gleaned a clue. Great detective work. Thank you Harald.

Lyfte