Edit

Resolve errors and warnings for compiler options and build configuration

This article covers the following compiler errors and warnings:

  • CS0006: Metadata file 'file' could not be found
  • CS0007: Unexpected common language runtime initialization error — 'description'
  • CS0016: Could not write to output file 'file' -- 'reason'
  • CS1564: Conflicting options specified: Win32 resource file; Win32 manifest
  • CS1616: Option 'option' overrides attribute 'attribute' given in a source file or added module
  • CS1668: Invalid search path 'path' specified in 'option' -- 'reason'
  • CS1719: Error opening Win32 resource file 'file' -- 'reason'
  • CS1773: Invalid version for /subsystemversion. The version must be 6.02 or greater for ARM or AppContainerExe, and 4.00 or greater otherwise
  • CS2008: No source files specified.
  • CS2019: Invalid target type for /target: must specify 'exe', 'winexe', 'library', or 'module'
  • CS2029: Invalid name for a preprocessing symbol; 'identifier' is not a valid identifier
  • CS2032: Character 'character' is not allowed on the command-line or in response files
  • CS2036: The /pdb option requires that the /debug option also be used
  • CS2038: The language name 'name' is invalid.
  • CS2039: Command-line syntax error: Invalid Guid format 'value' for option 'option'
  • CS2040: Command-line syntax error: Missing Guid for option 'option'
  • CS2041: Invalid output name: name
  • CS2042: Invalid debug information format: format
  • CS2043: 'id#' syntax is no longer supported. Use '$id' instead.
  • CS2044: /sourcelink switch is only supported when emitting PDB.
  • CS2045: /embed switch is only supported when emitting a PDB.
  • CS2046: Command-line syntax error: 'value' is not a valid value for the 'option' option. The value must be of the form 'format'.
  • CS3012: You must specify the CLSCompliant attribute on the assembly, not the module, to enable CLS compliance checking
  • CS3013: Added modules must be marked with the CLSCompliant attribute to match the assembly
  • CS7038: Failed to emit module 'module': error
  • CS8111: Invalid instrumentation kind: instrumentation kind
  • CS8113: Invalid hash algorithm name: 'hash algorithm name'
  • CS8190: Provided source code kind is unsupported or invalid: 'source code kind'
  • CS8191: Provided documentation mode is unsupported or invalid: 'documentation mode'.
  • CS8202: Public signing is not supported for netmodules.
  • CS8308: Do not use refout when using refonly.
  • CS8309: Cannot compile net modules when using /refout or /refonly.
  • CS8357: The specified version string 'version string' contains wildcards, which are not compatible with determinism. Either remove wildcards from the version string, or disable determinism for this compilation
  • CS8751: Internal error in the C# compiler.
  • CS8771: Output directory could not be determined
  • CS8772: stdin argument '-' is specified, but input has not been redirected from the standard input stream.
  • CS9400: Invalid 'option' value: 'value'. Accepted values are: 'value1, value2, ...'

Input and output file errors

  • CS0006: Metadata file 'file' could not be found
  • CS0016: Could not write to output file 'file' -- 'reason'
  • CS1668: Invalid search path 'path' specified in 'option' -- 'reason'
  • CS1719: Error opening Win32 resource file 'file' -- 'reason'
  • CS2008: No source files specified.

These errors indicate that the compiler can't find, read, or write files needed for compilation. For the full list of file-related compiler options, see C# compiler options - Inputs and C# compiler options - Resources.

  • Verify the path you pass to References or related options points to an existing assembly (CS0006). This error typically occurs when an assembly reference in the project file or command line specifies a path that doesn't exist. Check for typos, ensure the referenced project is built, and confirm the file isn't moved or deleted.
  • Check the output path to make sure it exists and is writable, and ensure no process currently has a lock on the file (CS0016). For example, make sure your executable isn't running when you attempt to build. If a previously built file is already at the location, verify that it isn't read-only.
  • Verify that the path you supply to AdditionalLibPaths or the LIB environment variable exists and is accessible (CS1668). The error message in single quotation marks contains the operating system error that explains why the path is invalid.
  • Correct the problem described in the error reason for the Win32 resource file (CS1719). The most common causes are "file not found" (verify the path) or "access denied" (check file permissions).
  • Pass at least one source-code file to the compiler (CS2008). This error occurs when you specify compiler options but don't provide any .cs files as input.

Invalid option values

  • CS1773: Invalid version for /subsystemversion. The version must be 6.02 or greater for ARM or AppContainerExe, and 4.00 or greater otherwise
  • CS2019: Invalid target type for /target: must specify 'exe', 'winexe', 'library', or 'module'
  • CS2029: Invalid name for a preprocessing symbol; 'identifier' is not a valid identifier
  • CS2032: Character 'character' is not allowed on the command-line or in response files
  • CS2038: The language name 'name' is invalid.
  • CS2039: Command-line syntax error: Invalid Guid format 'value' for option 'option'
  • CS2040: Command-line syntax error: Missing Guid for option 'option'
  • CS2041: Invalid output name: name
  • CS2042: Invalid debug information format: format
  • CS2043: 'id#' syntax is no longer supported. Use '$id' instead.
  • CS2046: Command-line syntax error: 'value' is not a valid value for the 'option' option. The value must be of the form 'format'.
  • CS8772: stdin argument '-' is specified, but input has not been redirected from the standard input stream.
  • CS9400: Invalid 'option' value: 'value'. Accepted values are: 'value1, value2, ...'

These errors indicate that a value you passed to a compiler option is malformed or outside the allowed set of values. For the full list of compiler options, see C# Compiler Options.

  • Supply a valid version number for the SubsystemVersion option (CS1773). ARM and AppContainerExe targets require version 6.02 or greater; other targets require 4.00 or greater.
  • Use one of the valid OutputType values: exe, winexe, library, or module (CS2019). The compiler rejects any other value for the /target option.
  • Ensure preprocessing symbols you pass to DefineConstants are valid C# identifiers (CS2029). Identifiers must start with a letter or underscore and contain only letters, digits, or underscores. You can't suppress this warning by using the NoWarn option.
  • Remove ASCII control characters (range 0–31) and the pipe (|) character from command-line arguments and response files (CS2032). The command-line processor and IDE typically filter these characters, so this error most commonly appears when you use response files that contain invalid characters. Newer versions of the compiler don't generate this error.
  • Supply a valid culture name recognized by the compiler (CS2038). Check the spelling against the list of supported culture names.
  • Provide a properly formatted GUID for options that require one, such as /checksumalgorithm (CS2039, CS2040). The GUID must follow the standard format (for example, xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
  • Remove invalid characters from the output file name (CS2041). Output names can't contain characters that are invalid in file paths on the target operating system.
  • Provide a valid debug information format value (CS2042). Accepted values depend on the compiler version and typically include full, pdbonly, portable, and embedded.
  • Replace the legacy id# syntax with $id (CS2043). The compiler no longer supports the older syntax.
  • Supply a value that matches the expected format for the specified option (CS2046). The error message indicates the expected form.
  • Redirect standard input when using the - (stdin) argument (CS8772). The compiler expects piped input when you pass - as the source file argument. Use a pipeline (for example, cat file.cs | csc -) or remove the - argument and pass the source file directly.
  • Use one of the accepted values listed in the error message for the named compiler option (CS9400). This error is a general-purpose diagnostic that the compiler reports whenever a compiler feature or property accepts only a fixed set of values and you supply one that isn't in that set. For example, you might see this error when you provide an unrecognized value for the updated-memory-safety-rules compiler feature. Check the documentation for the specific option named in the error to find its accepted values.

Instrumentation and PDB options

  • CS8111: Invalid instrumentation kind: instrumentation kind
  • CS8113: Invalid hash algorithm name: 'hash algorithm name'

Use a supported instrumentation kind when you pass the /instrument option. The command-line option accepts TestCoverage; Roslyn API consumers must provide a valid InstrumentationKind value in EmitOptions.InstrumentationKinds (CS8111).

Provide a cryptographic hash algorithm supported by the current platform in EmitOptions.PdbChecksumAlgorithm (CS8113). Deterministic emission also requires a nonempty PDB checksum algorithm. This API setting calculates the PDB checksum stored in the compiled file. It's distinct from the ChecksumAlgorithm compiler option, which selects SHA1 or SHA256 for source-file checksums stored in the PDB. Invalid command-line values are rejected while parsing the command line rather than reported as CS8113.

Parse and documentation API options

  • CS8190: Provided source code kind is unsupported or invalid: 'source code kind'
  • CS8191: Provided documentation mode is unsupported or invalid: 'documentation mode'.

Ordinary csc command-line option parsing doesn't produce these public Roslyn API diagnostics. When a CSharpParseOptions instance contains an invalid enum value, CSharpParseOptions.Errors exposes them. CSharpCompilation.GetDiagnostics() also reports them after a syntax tree that uses those options is included in a compilation, but CSharpSyntaxTree.GetDiagnostics() doesn't report them.

Conflicting or missing options

  • CS1564: Conflicting options specified: Win32 resource file; Win32 manifest
  • CS1616: Option 'option' overrides attribute 'attribute' given in a source file or added module
  • CS2036: The /pdb option requires that the /debug option also be used
  • CS2044: /sourcelink switch is only supported when emitting PDB.
  • CS2045: /embed switch is only supported when emitting a PDB.
  • CS8771: Output directory could not be determined

These errors indicate that compiler options contradict each other, override source-level attributes, or require companion options that you didn't specify. For the full list of compiler options, see C# Compiler Options.

  • Include the custom Win32 manifest inside the Win32 resource file and remove the /win32manifest compiler option (CS1564). You can't specify both Win32Resource and Win32Manifest simultaneously. If you use /Win32res, include the manifest in the resource file.
  • Remove the conflicting source attribute or the conflicting command-line option so they don't contradict each other (CS1616). This warning occurs when assembly attributes like AssemblyKeyFileAttribute or AssemblyKeyNameAttribute in source conflict with the KeyFile or KeyContainer command-line option.
  • Add the /debug compiler option when using PdbFile, or remove the /pdb option (CS2036). Program database files are only generated for debug builds, so /pdb is meaningless without /debug. For more information, see DebugType (C# Compiler Options).
  • Add the /debug option (or set DebugType in the project) to enable PDB generation when using /sourcelink or /embed (CS2044, CS2045). Source links and embedded source both require PDB output because the source information is stored in the PDB file.
  • Ensure the project or command line specifies a valid output directory (CS8771). Verify the OutputPath or OutDir property in your project file, or pass a valid /out: argument to the compiler.

Module and assembly configuration

  • CS3012: You must specify the CLSCompliant attribute on the assembly, not the module, to enable CLS compliance checking
  • CS3013: Added modules must be marked with the CLSCompliant attribute to match the assembly

These warnings involve mismatches between the CLSCompliant attribute on modules and assemblies. For more information on the CLS, see Language independence and language-independent components.

  • Build with the module element of the OutputType compiler option when specifying [module:System.CLSCompliant(true)] (CS3012). The CLSCompliant attribute on a module is only meaningful when the output target is a module rather than an assembly.
  • Add a matching [module:CLSCompliant(true)] or [module:CLSCompliant(false)] attribute to modules added via AddModule so they agree with the assembly's CLS state (CS3013). The default is [module:CLSCompliant(false)], so modules that should be CLS compliant must explicitly opt in.

Public signing and reference assembly output

  • CS8202: Public signing is not supported for netmodules.
  • CS8308: Do not use refout when using refonly.
  • CS8309: Cannot compile net modules when using /refout or /refonly.

A netmodule contains metadata and compiled code but no assembly manifest. Because public signing applies a public key and signed flag to an assembly manifest, don't combine PublicSign with the module OutputType (CS8202). Produce an assembly, or disable public signing for the netmodule.

The /refout option produces a reference assembly in addition to the implementation assembly. The /refonly option produces only a reference assembly as the primary output. Remove /refout when using /refonly (CS8308). Reference assemblies require an assembly manifest, so don't combine either option with /target:module (CS8309). For MSBuild projects, use ProduceReferenceAssembly or ProduceOnlyReferenceAssembly, but not both.

Deterministic assembly versions

  • CS8357: The specified version string 'version string' contains wildcards, which aren't compatible with determinism. Either remove wildcards from the version string, or disable determinism for this compilation.

Deterministic compilation requires the same inputs to produce the same output. A wildcard in AssemblyVersionAttribute derives part of the version from changing values, so it isn't compatible with Deterministic compilation. Replace the wildcard with fixed numeric components. Disable deterministic compilation only when a generated wildcard version is required.

Compiler infrastructure errors

  • CS0007: Unexpected common language runtime initialization error — 'description'
  • CS7038: Failed to emit module 'module': error
  • CS8751: Internal error in the C# compiler.

These errors indicate failures in the compiler's own infrastructure rather than problems with your source code or command-line options.

  • Verify that the runtime version specified in csc.exe.config is installed and not corrupted (CS0007). The setup process configures this file and you shouldn't change it. If you modified the file, check that the specified runtime version is present on the machine. If the correct version is present but might be corrupted, reinstall the common language runtime. Newer versions of the compiler no longer generate this error and it doesn't apply to the modern dotnet build toolchain.
  • Try a clean rebuild, verify all assembly references are valid and not corrupted, and check for conflicting reference versions (CS7038). This error wraps a lower-level failure during the assembly emit phase. The nested error message provides more specific details about what went wrong.
  • File an issue in the Roslyn repository with a minimal reproduction (CS8751). This error indicates a bug in the compiler itself. Your code exposed a code path the compiler team didn't anticipate.