Search code examples
c#wpfauto-generatebuild-error

Solution fails to build w/ missing auto-generated .g.cs file for the first time, succeeds on second build


I'm building a WPF app w/ Visual Studio 2015 (Update 3), and—at least by now, I'm not sure for how long this has been the case—every time I make a change and compile, I'll get a failed build w/ the error

6>CSC : error CS2001: Source file 'C:[...]\Obj\Debug\AnyCPU\GeneratedInternalTypeHelper.g.cs' could not be found.`

If I just build a second time, though, it works just fine.

This smells to me like a dependency on another file that is generated afterwards or something like that, but I haven't been able to find out what it is, a google search didn't net anything either, and neither did a search through my project what this file is used for in the first place (the name suggests its purpose, but I don't know where exactly it is used).

It might also be that the (group-policy-mandated) Anti-Virus is holding an exclusive lock on the file or its dependency for a moment too long, and VS stumbles over that, I think I remember a problem like this at my last job, but I'm not sure that is the case (and I can't simply disable the scanner for a check, it's completely locked down and I don't want to violate company policy for trying to circumvent it).

Any ideas? It's not critical since it's easy to work around, but it's annoying and I don't really want to check in the project like this in the end.


Solution

  • I had the same issue and i found why it happened (in my case).

    Every project of our solution has the same output folder. The file GeneratedInternalTypeHelper.g.cs was generated at the same place for each project. The build order/dependencies were computed and Visual Studio found that some project could be build in parallel.

    In Tools > Options > Project & Solutions > Build and Run you can find the option "Maximum number of parallel project builds.

    After changed from 8(in my case) to 1, no more files generated at the same time :) It is a little slower to compile but really less annoying than compile multiple times... \o/