The F1 online help (MSDN) does not faithfully reflect your actual API available
2024年5月14日When writing code in Visual Studio, do you often press F1 and check the online documentation of your interested API? If so, you are bound to be suprised that MSDN (https://learn.microsoft.com/ or https://learn.microsoft.com/en-us/dotnet/) can deceive you!
Differed Class Descriptions
Check the class description of System.Diagnostics.Debug
. The website Microsoft Learn says this class “Provides a set of methods and properties that help debug your code.”, but the Intellisense in your IDE says this class “Provides a set of properties and methods for debugging code.”
History Check
The distinction is not due to version mismatch. I made a table for you.
site | Class description |
---|---|
learn.microsoft.com | help debug your code |
.NET 8.0 | for debugging code |
.NET Core 3.1 | for debugging code |
.NET Framework | for debugging code |
MSDN 2014 (.NET Framework 1.1) | help debug your code |
The table summarizes the class description of the Debug class since .NET Framework 1.1 to .NET 8.0, and since the age of MSDN to the present Microsoft Learn. It turns out, the XML documentation of this class has always been “for debugging code”, and the online description of this class has always been “help debug your code”.
More Discrepancies
Although the two kinds of description mean the same in English, they break equivalence dramastically in a sense of formal method. The API reference team is self-governed. They are free to write documents in their own way, which may or may not match the actual product they are documenting.
The Debug class bears more discrepancies to discover. I list a couple for you.
For starters, in the code the method WriteLine
has no XML documentation, but the API reference online somehow hallucinated “Writes information about the debug to the trace listeners in the Listeners collection.” It is not a version issue. You can check yourself.
Next, the source code has a SetProvider
method. This method stub is blatently missing online.
Conclusion
Unlike Java or Python, the API reference online for .NET Runtime/.NET Core/.NET Framework is not a superset of the XML documentation of the product. The API reference team is free to hallucinate or overwrite the XML documentation that the C# developers provide.
The code snippets provided in API references do not run under the targeted runtime. (Otherwise the code in Examples referencing Listeners
will not pass syntax check and will not be published.)
The method stubs (or signatures) can be missing or differed from the actual product, let alone text descriptions.