Error CS0656 is incomprehensible and misleading. #25465
Labels
Area-Compilers
Bug
Concept-Diagnostic Clarity
The issues deals with the ease of understanding of errors and warnings.
Language-C#
Milestone
Version Used: .Net Core 2.1.100
When you compile code that uses dynamic, the compiler generates calls to various support functions. These functions are defined in the Microsoft.CSharp package. If this package isn't referenced, it generates CS0656.
This error, its message, and its help page are remarkably unhelpful.
OK, so it is missing some member. As a new programmer, I'm baffled. Am I supposed to implement this? Is my installation corrupted? Why doesn't the language just work?
But VS allows me to get more information, by putting the cursor on the error in the output window and pressing F1. This leads me here:
https://docs.microsoft.com/en-us/dotnet/csharp/misc/cs0656?f1url=https%3A%2F%2Fmsdn.microsoft.com%2Fquery%2Fdev15.query%3FappId%3DDev15IDEF1%26l%3DEN-US%26k%3Dk(CS0656)%3Bk(vs.output)%3Bk(SolutionItemsProject)%26rd%3Dtrue
This page suggests that one of two things is happening, and I quote:
I check my references. Nope, not doing anything like the second option says. In fact, my test project references nothing except NETStandard. Nor does the project itself contain anything like it.
So it's gotta be the first option, right? My installation is corrupt? Should I reinstall? Will it work then? (Hint: it won't.)
So thankfully I'm actually experienced enough to not reinstall, and first search the web a little more. Which leads me to the actual problem (not referencing Microsoft.CSharp) and the solution (installing it). But the user experience in this case was abysmal. Furthermore, this error appeared only after my latest round of dependency upgrades (I suspect I was previously indirectly referencing the package), so the code worked previously "out of the box".
The compiler error should be more helpful than that. Modern compilers usually give solution hints (see: Clang, rustc, many more). In this case, "A language feature package may be missing." would be a good hint even if you don't want to map from the missing function to the probably containing package.
The help page for the error is just inacceptable. I have added a comment with the real fix, but this should be in a most prominent place of the actual text.
The text was updated successfully, but these errors were encountered: