Skip to content

Add build-only diagnostic note to CS0169 documentation #47309

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ ms.assetid: b0b61cbb-c9a7-48c9-9e60-7cdd5ecb3e6c

Predefined type 'type' is not defined or imported

The main cause for this problem is that the project is not importing mscorlib.dll, which defines the entire System namespace. This can be caused by one of the following:
The main cause for this problem is that the project is not importing mscorlib.dll, which defines the entire System namespace. This can be caused by one of the following:

[!INCLUDE[csharp-build-only-diagnostic-note](~/includes/csharp-build-only-diagnostic-note.md)]

- The [**NoStandardLib**](../compiler-options/advanced.md#nostandardlib) option from the command line compiler has been specified. The **NoStandardLib** option prevents the import of mscorlib.dll. Use this option if you want to define or create a user-specific System namespace.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ ms.assetid: 6b378974-fdd9-451b-b595-6b5b19b4ab48

Property, indexer, or event 'name' is not supported by the language; try directly calling accessor method 'name!'

This error occurs when using imported metadata that was generated by another compiler. Your code attempted to use a class member that the compiler cannot process.
This error occurs when using imported metadata that was generated by another compiler. Your code attempted to use a class member that the compiler cannot process.

[!INCLUDE[csharp-build-only-diagnostic-note](~/includes/csharp-build-only-diagnostic-note.md)]

## Example 1

Expand Down
2 changes: 2 additions & 0 deletions docs/csharp/language-reference/compiler-messages/cs1607.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ ms.assetid: 7ad8e1a4-40c2-41cc-b4ee-cc4d7beb4372
Assembly generation -- reason

A warning was generated from the assembly-creation phase of the compilation.

[!INCLUDE[csharp-build-only-diagnostic-note](~/includes/csharp-build-only-diagnostic-note.md)]

If you are building a 64-bit application on a 32-bit operating system, you must ensure that 64-bit versions of all referenced assemblies are installed on the target operating system.

Expand Down
2 changes: 2 additions & 0 deletions docs/csharp/language-reference/compiler-messages/cs8178.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ helpviewer_keywords:

'await' cannot be used in an expression containing a call to because it returns by reference

[!INCLUDE[csharp-build-only-diagnostic-note](~/includes/csharp-build-only-diagnostic-note.md)]

## Example

The following sample generates CS8178:
Expand Down
2 changes: 2 additions & 0 deletions docs/csharp/misc/cs0017.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ ms.assetid: 5e2a3eb3-6f6e-485d-8293-ceabea4d6905
Program 'output file name' has more than one entry point defined. Compile with /main to specify the type that contains the entry point.

A program can only have one [Main](../fundamentals/program-structure/main-command-line.md) method.

[!INCLUDE[csharp-build-only-diagnostic-note](~/includes/csharp-build-only-diagnostic-note.md)]

To resolve this error, you can either delete all Main methods in your code, except one, or you can use the [**StartupObject**](../language-reference/compiler-options/advanced.md#mainentrypoint-or-startupobject) compiler option to specify which Main method you want to use.

Expand Down
2 changes: 2 additions & 0 deletions docs/csharp/misc/cs0028.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ ms.assetid: 47df919f-01fa-45ae-a4b7-912445e679e2
'function declaration' has the wrong signature to be an entry point

The method declaration for `Main` was invalid: it was declared with an invalid signature. `Main` must be declared as static and it must return either [int](../language-reference/builtin-types/integral-numeric-types.md) or [void](../language-reference/builtin-types/void.md). For more information, see [Main() and Command-Line Arguments](../fundamentals/program-structure/main-command-line.md).

[!INCLUDE[csharp-build-only-diagnostic-note](~/includes/csharp-build-only-diagnostic-note.md)]

The following sample generates CS0028:

Expand Down
2 changes: 2 additions & 0 deletions docs/csharp/misc/cs0067.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ ms.assetid: df75220b-0b93-45ec-8655-98d9333b0bb7
The event 'event' is never used

An [event](../language-reference/keywords/event.md) was declared but never used in the class in which it was declared.

[!INCLUDE[csharp-build-only-diagnostic-note](~/includes/csharp-build-only-diagnostic-note.md)]

The following sample generates CS0067:

Expand Down
4 changes: 3 additions & 1 deletion docs/csharp/misc/cs0148.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ ms.assetid: d199afbf-02e1-4a1c-9e36-07bf86f1a2fb

The delegate 'delegate' does not have a valid constructor

You imported and used a managed program (one that uses the .NET runtime) that was created with another compiler. That compiler allowed an ill-formed [delegate](../language-reference/builtin-types/reference-types.md) constructor. For more information, see [Delegates](../programming-guide/delegates/index.md).
You imported and used a managed program (one that uses the .NET runtime) that was created with another compiler. That compiler allowed an ill-formed [delegate](../language-reference/builtin-types/reference-types.md) constructor. For more information, see [Delegates](../programming-guide/delegates/index.md).

[!INCLUDE[csharp-build-only-diagnostic-note](~/includes/csharp-build-only-diagnostic-note.md)]
2 changes: 2 additions & 0 deletions docs/csharp/misc/cs0169.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ ms.assetid: 04b0015f-658d-440a-b9ba-831178f1a180
The private field 'class member' is never used

A private variable was declared but never referenced. A common way to generate this warning is when you declare a private member of a class and do not use it.

[!INCLUDE[csharp-build-only-diagnostic-note](~/includes/csharp-build-only-diagnostic-note.md)]

The following sample generates CS0169:

Expand Down
4 changes: 3 additions & 1 deletion docs/csharp/misc/cs0204.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ ms.assetid: c1811479-41b3-4a0b-9160-ecc14bf255a3

Only 65534 locals are allowed

The limit of 65534 local variables has been exceeded in a method.
The limit of 65534 local variables has been exceeded in a method.

[!INCLUDE[csharp-build-only-diagnostic-note](~/includes/csharp-build-only-diagnostic-note.md)]
2 changes: 2 additions & 0 deletions docs/csharp/misc/cs0402.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ ms.assetid: 5a252c95-18c7-4569-bae0-e1f7b582cf6a
'identifier' : an entry point cannot be generic or in a generic type

The entry point was found in a generic type. To remove this warning, implement Main in a non-generic class or struct.

[!INCLUDE[csharp-build-only-diagnostic-note](~/includes/csharp-build-only-diagnostic-note.md)]

```csharp
// CS0402.cs
Expand Down
2 changes: 2 additions & 0 deletions docs/csharp/misc/cs0414.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ ms.assetid: 6a0a80be-799b-4d9c-a7e0-6b91e9ce7be0

The private field 'field' is assigned but its value is never used

[!INCLUDE[csharp-build-only-diagnostic-note](~/includes/csharp-build-only-diagnostic-note.md)]

This warning can occur in several scenarios in which the compiler can verify that a variable is never referenced:

- A private field is assigned a constant value but is never subsequently read. The unnecessary assignment could effect performance. Consider removing the field.
Expand Down
2 changes: 2 additions & 0 deletions docs/csharp/misc/cs0649.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ ms.assetid: 37137b18-12ed-4a0f-92e6-ee5fb0532ef3
Field 'field' is never assigned to, and will always have its default value 'value'

The compiler detected an uninitialized private or internal field declaration that is never assigned a value.

[!INCLUDE[csharp-build-only-diagnostic-note](~/includes/csharp-build-only-diagnostic-note.md)]

The following sample generates CS0649:

Expand Down
4 changes: 3 additions & 1 deletion docs/csharp/misc/cs0656.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ ms.assetid: e695280a-e75d-4e8c-aec2-1f3fb455544a

Missing compiler required member 'object.member'

One of the following problems exists:
One of the following problems exists:

[!INCLUDE[csharp-build-only-diagnostic-note](~/includes/csharp-build-only-diagnostic-note.md)]

- Your installation of the common language runtime is corrupt.

Expand Down
4 changes: 3 additions & 1 deletion docs/csharp/misc/cs1555.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ ms.assetid: 1919c8b8-d72c-44af-91d0-674ccde77c3f

Could not find 'class' specified for Main method

A class was specified to the [**MainEntryPoint**](../language-reference/compiler-options/advanced.md#mainentrypoint-or-startupobject) compiler option, but the class name was not found in the source code.
A class was specified to the [**MainEntryPoint**](../language-reference/compiler-options/advanced.md#mainentrypoint-or-startupobject) compiler option, but the class name was not found in the source code.

[!INCLUDE[csharp-build-only-diagnostic-note](~/includes/csharp-build-only-diagnostic-note.md)]
4 changes: 3 additions & 1 deletion docs/csharp/misc/cs1556.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ ms.assetid: 960307d2-d815-4d7a-8f96-e3e78c038ade

'construct' specified for Main method must be a valid class or struct

The [**MainEntryPoint**](../language-reference/compiler-options/advanced.md#mainentrypoint-or-startupobject) compiler option was passed an identifier that was not a class name.
The [**MainEntryPoint**](../language-reference/compiler-options/advanced.md#mainentrypoint-or-startupobject) compiler option was passed an identifier that was not a class name.

[!INCLUDE[csharp-build-only-diagnostic-note](~/includes/csharp-build-only-diagnostic-note.md)]
6 changes: 4 additions & 2 deletions docs/csharp/misc/cs1558.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ ms.assetid: ee603d66-007e-4782-9285-7ff031975f0f

'class' does not have a suitable static Main method

The [**MainEntryPoint**](../language-reference/compiler-options/advanced.md#mainentrypoint-or-startupobject) compiler option specified a class in which to look for a **Main** method. However, the [Main](../fundamentals/program-structure/main-command-line.md) method was not defined correctly.
The [**MainEntryPoint**](../language-reference/compiler-options/advanced.md#mainentrypoint-or-startupobject) compiler option specified a class in which to look for a **Main** method. However, the [Main](../fundamentals/program-structure/main-command-line.md) method was not defined correctly.

[!INCLUDE[csharp-build-only-diagnostic-note](~/includes/csharp-build-only-diagnostic-note.md)]

The following example generates CS1558 because of invalid return type.
The following example generates CS1558 because of invalid return type.

```csharp
// CS1558.cs
Expand Down
2 changes: 2 additions & 0 deletions docs/csharp/misc/cs5001.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Program does not contain a static 'Main' method suitable for an entry point

This error occurs when no static `Main` method with a correct signature is found in the code that produces an executable file. It also occurs if the entry point function, `Main`, is defined with the wrong case, such as lower-case `main`. For information about the rules that apply to the `Main` method, see [Main() and Command-Line Arguments](../fundamentals/program-structure/main-command-line.md).

[!INCLUDE[csharp-build-only-diagnostic-note](~/includes/csharp-build-only-diagnostic-note.md)]

If the `Main` method has an `async` modifier, make sure that the [selected C# language version](../language-reference/configure-language-version.md) is 7.1 or higher and to use `Task` or `Task<int>` as the return type.

The `Main` method is only required when compiling an executable file, that is, when the **exe** or **winexe** element of the [**TargetType**](../language-reference/compiler-options/output.md#targettype) compiler option is specified. The following Visual Studio project types specify one of these options by default:
Expand Down
2 changes: 2 additions & 0 deletions includes/csharp-build-only-diagnostic-note.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
> [!NOTE]
> This warning is only reported during explicit **Build** or **Rebuild** operations. It does not appear during typing in the IDE as part of IntelliSense diagnostics. This means that if you fix the warning by using the field or removing it, the warning might persist in the error list until you build or rebuild the project again.
Loading