Working on a C# project, I recently encountered a puzzling problem that made me go crazy for a couple of hours. After pulling the latest source code from our version control system, the solution won't run anymore, giving plenty of build errors from out of left field.
Here are what the errors were basically saying:
- XXXX.XXXX does not contain a definition for YYYY and no extension method YYYY accepting a first argument of type XXXX.XXXX could be found (are you missing a using directive or an assembly reference?)
- XXXX.XXXX.XXXX does not contain a definition for YYYY
- The type name YYYY does not exist in the type XXXX.XXXX
Taking a look at where the errors point though, they don't make sense. XXXX.XXXX does contain a definition for YYYY (errors 1 and 2), and YYYY actually exists in XXXX.XXXX (error 3). I can see the definitions and the existence of the classes, and Visual Studio does recognize them, but it doesn't see them during build!
I've tried cleaning the solution, rebuilding the solution, re-fetching the files from version control, restarting Visual Studio and restarting the PC but to no avail. The errors persist! Visual Studio continued to give the "false" errors, so out of desperation, I just tried doing this:
I removed YYYY in XXXX.XXXX (by cutting the code block), and gave it a Build. It produced the same errors, but this time, it's already a true error, since YYYY doesn't really exist anymore. Then I put YYYY back (by pasting the code block), and gave it another Build. This time the errors were no more! Success! It's running again!
Maybe the errors had something to do with the project files modified outside Visual Studio during the merge process. Maybe I'll get to the bottom of that some other time. But should I encounter Visual Studio giving false errors again, I know what to do. CBPB. Cut, Build, Paste, Build. Solved!
No comments:
Post a Comment