Errata

Programming C# 8.0

Errata for Programming C# 8.0

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

Color Key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted by Date submitted
Page 22
2nd paragraph


I'm having trouble with the first program on page 22 of the book.

The program is:

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace HelloWorld.Tests
{
[TestClass]
public class WhenProgramRuns
{
private string _consoleOutput;

[TestInitialize]
public void Initialize()
{
var w = new System.IO.StringWriter();
Console.SetOut(w);

Program.Main(new string[0]);

_consoleOutput = w.GetStringBuilder().ToString().Trim();
}
[TestMethod]
public void SaysHelloWorld()
{
Assert.AreEqual("Hello, World!", _consoleOutput);
}
}
}

I'm using VS 2019
Microsoft Visual Studio Community 2019
Version 16.11.11

Microsoft.NET Framework
Version 4.8.04084

There's a difference between the book and my code.
The line in the book:
Program.Main(new string[0]);

gets replaced by VS2019 with:
AutoGeneratedProgram.Main(new string[0]);

I have tried compiling with and without the "AutoGenerated" part but the
compile fails.

I get the error:

Build started...
1>------ Build started: Project: HelloWorld, Configuration: Debug Any CPU ------
1>HelloWorld -> J:\Programming\Book_C#_8.0\HelloWorld\HelloWorld\bin\Debug\netcoreapp3.1\HelloWorld.dll
2>------ Build started: Project: HelloWorld.Test, Configuration: Debug Any CPU ------
2>J:\Programming\Book_C#_8.0\HelloWorld\HelloWorld.Test\WhenProgramRuns.cs(17,34,17,38): error CS0122: 'AutoGeneratedProgram.Main(string[])' is inaccessible due to its protection level
2>Done building project "HelloWorld.Test.csproj" -- FAILED.
========== Build: 1 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

if I use the line Program.Main(new string[0]); I get the same except

error CS0122: 'Program.Main(string[])' is inaccessible due to its protection level

Can you help from this information?
What am I doing wrong ?

Thank you.

Jim Snively

Note from the Author or Editor:
Have you done the step described on the following page, illustrated in Example 1-3? As the book goes on to explain directly after showing the example you're referring to, we need to make a change to the code under test "to make the code accessible to the test" as the book says in the final paragraph on page 23. I would expect to see the error you've described until you've made that change.

Jim Snively  Mar 31, 2022 
Printed Page 382
1st line

Typo in markup led to markup text being printed: "pass[<span class="keep together">delegate</span>]" should have been "delegate"

Erik Zijp  Sep 11, 2020 
Printed Page 616
1st paragraph under the heading "Position and Seeking"

The title sentence appears to start in the middle of the sentence.

"
tion property")))Streams automatically...
"

Anonymous  Aug 18, 2020