Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error CS0656 is incomprehensible and misleading. #25465

Open
CornedBee opened this issue Mar 14, 2018 · 1 comment
Open

Error CS0656 is incomprehensible and misleading. #25465

CornedBee opened this issue Mar 14, 2018 · 1 comment
Labels
Area-Compilers Bug Concept-Diagnostic Clarity The issues deals with the ease of understanding of errors and warnings. Language-C#
Milestone

Comments

@CornedBee
Copy link

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.

error CS0656: Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.Binder.SetMember'

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:

  • Your installation of the common language runtime is corrupt.
  • You have a reference to an assembly that defines a type that is also found in the common language runtime. However, your assembly's type is not defined the way the C# compiler expects.

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.

@svick
Copy link
Contributor

svick commented Mar 14, 2018

As far as I can see, there are two problems here:

  1. The compiler error is hard to understand.
  2. The documentation page is incorrect.

This repo should be the right one for the first problem, but I think you should open a separate issue in the dotnet/docs repo for the second problem, because that's where the source for that page is.

@sharwell sharwell added Language-C# Area-Compilers Concept-Diagnostic Clarity The issues deals with the ease of understanding of errors and warnings. labels Mar 14, 2018
@jaredpar jaredpar added this to the Unknown milestone Aug 31, 2018
@gafter gafter added the Bug label Sep 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Bug Concept-Diagnostic Clarity The issues deals with the ease of understanding of errors and warnings. Language-C#
Projects
None yet
Development

No branches or pull requests

5 participants