Skip to content

Latest commit

 

History

History
180 lines (141 loc) · 10.3 KB

File metadata and controls

180 lines (141 loc) · 10.3 KB
title Resolve errors for incorrect or missing assembly references
description These compiler errors and warnings indicate incorrect or missing assembly references. These errors cause missing or incorrect definitions for types in your program.
f1_keywords
CS0012
CS0234
CS0246
CS0400
CS1068
CS1069
CS1070
CS1683
CS1704
CS1714
CS1760
CS7008
CS7068
CS7069
CS7071
CS7079
CS8090
CS8203
CS9286
helpviewer_keywords
CS0012
CS0234
CS0246
CS0400
CS1068
CS1069
CS1070
CS1683
CS1704
CS1714
CS1760
CS7008
CS7068
CS7069
CS7071
CS7079
CS8090
CS8203
CS9286
ms.date 03/03/2026
ai-usage ai-assisted

Resolve errors and warnings related to assembly references

  • CS0012: The type 'type' is defined in an assembly that is not referenced. You must add a reference to assembly 'assembly'.
  • CS0234: The type or namespace name does not exist in the namespace (are you missing an assembly reference?)
  • CS0246: The type or namespace name could not be found (are you missing a using directive or an assembly reference?)
  • CS0400: The type or namespace name could not be found in the global namespace (are you missing an assembly reference?)
  • CS0735: Invalid type specified as an argument for xref:System.Runtime.CompilerServices.TypeForwardedToAttribute attribute.
  • CS1068: The type name could not be found in the global namespace. This type has been forwarded to another assembly. Consider adding a reference to that assembly.
  • CS1069: The type name could not be found in the namespace. This type has been forwarded to another assembly. Consider adding a reference to that assembly.
  • CS1070: The type name could not be found. This type has been forwarded to another assembly. Consider adding a reference to that assembly.
  • CS1704: An assembly with the same simple name has already been imported. Try removing one of the references or sign them to enable side-by-side.
  • CS1714: The base class or interface of this type could not be resolved or is invalid.
  • CS1760: Multiple assemblies refer to the same metadata but only one is a linked reference (specified using /link option); consider removing one of the references.
  • CS7008: The assembly name is reserved and cannot be used as a reference in an interactive session.
  • CS7068: Reference to type claims it is defined in this assembly, but it is not defined in source or any added modules.
  • CS7069: Reference to type claims it is defined in another assembly, but it could not be found.
  • CS7071: Assembly reference is invalid and cannot be resolved.
  • CS7079: The type is defined in a module that has not been added. You must add the module.
  • CS8090: There is an error in a referenced assembly.
  • CS8203: Invalid assembly name.
  • CS9286: Type does not contain a definition and no accessible extension member for receiver type could be found (are you missing a using directive or an assembly reference?)

In addition, the following warnings are covered in this article:

  • CS1683: Reference to type 'Type Name' claims it is defined in this assembly, but it is not defined in source or any added modules.

Missing references

The following errors and warnings indicate that you're missing an assembly reference:

  • CS0012: The type 'type' is defined in an assembly that is not referenced. You must add a reference to assembly 'assembly'.
  • CS0234: The type or namespace name does not exist in the namespace (are you missing an assembly reference?)
  • CS0246: The type or namespace name could not be found (are you missing a using directive or an assembly reference?)
  • CS9286: Type does not contain a definition and no accessible extension member for receiver type could be found (are you missing a using directive or an assembly reference?)

These compiler errors indicate one of these problems in your code:

  • The project doesn't reference the required assembly. To fix this error, add a reference to the required assembly.
  • You misspelled the name of a type. Check the name of the type.
  • You used a variable name where the name of a xref:System.Type?displayProperty=nameWithType was expected, such as in the typeof operator or the is operator.
  • You used the global scope operator, (::) when the type isn't in the global namespace.
  • You're accessing an extension member and either the namespace isn't specified in a using directive, or you're not referencing the assembly that contains the extension.

When the assembly appears to be referenced

If the assembly appears to be referenced in your project but you still receive CS0012, try these troubleshooting steps:

  • Restore packages: Run dotnet restore to ensure all package references are properly resolved, especially after installing or uninstalling NuGet packages.

  • Clear the NuGet package cache and restore:

    dotnet nuget locals all --clear
    dotnet restore
  • Check for version conflicts: Verify that all referenced assemblies use compatible versions. Look for binding redirect warnings in the build output.

  • Clean the solution and rebuild to ensure no stale references remain:

    dotnet clean
    dotnet build
  • Verify package integrity: If the error occurred after package operations, ensure the package was installed correctly by removing and reinstalling it:

    dotnet remove package [PackageName]
    dotnet add package [PackageName]

CS0012 in ASP.NET Framework web apps with Razor precompilation

In ASP.NET Framework web applications that use aspnet_compiler.exe to precompile Razor (.cshtml) views, you might see CS0012 errors after you upgrade a NuGet package—even though your regular build succeeds.

This error occurs when a NuGet package you're using (directly or transitively) depends on an assembly that's a facade on your target framework version—for example, System.ValueTuple, System.Runtime, netstandard, or System.Net.Http on .NET Framework 4.7 and later. Because these assemblies are part of the framework itself, NuGet doesn't copy their DLLs into your application's bin folder.

The MSBuild compiler resolves these references correctly during a normal build. However, aspnet_compiler.exe uses a separate mechanism: it reads assembly references from the bin folder and from the <compilation><assemblies> section of your web.config file. When the assembly isn't in either location, the Razor compiler can't find it and reports a CS0012 error.

Note

This error only affects .cshtml (Razor) files. Files like .aspx and .ascx compile with a different code path and don't have this limitation.

To fix the error, add the missing assembly to the <system.web><compilation><assemblies> section of your web.config file. The assembly name, version, and public key token come from the CS0012 error message:

<system.web>
  <compilation>
    <assemblies>
      <add assembly="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"/>
    </assemblies>
  </compilation>
</system.web>

Type forwarding

  • CS1068: The type name could not be found in the global namespace. This type has been forwarded to another assembly. Consider adding a reference to that assembly.
  • CS1069: The type name could not be found in the namespace. This type has been forwarded to another assembly. Consider adding a reference to that assembly.
  • CS1070: The type name could not be found. This type has been forwarded to another assembly. Consider adding a reference to that assembly.

These errors indicate an error referencing a type forwarded to a different assembly. To address any of these errors, add a reference to the assembly indicated in the error message.

Duplicate references

The following errors indicate a duplicate assembly reference:

  • CS1704: An assembly with the same simple name has already been imported. Try removing one of the references or sign them to enable side-by-side.
  • CS1760: Multiple assemblies refer to the same metadata but only one is a linked reference (specified using /link option); consider removing one of the references.

To fix these errors, you must either remove one of the references, or resolve the duplication. Causes for duplication include:

  • Multiple unsigned assemblies have the same name.
  • Your project references multiple versions of the same assembly.

Invalid assembly reference

The following errors indicate that an assembly reference is invalid:

  • CS7008: The assembly name is reserved and cannot be used as a reference in an interactive session.
  • CS7069: Reference to type claims it is defined in another assembly, but it could not be found.
  • CS7071: Assembly reference is invalid and cannot be resolved.
  • CS7079: The type is defined in a module that has not been added. You must add the module.
  • CS8090: There is an error in a referenced assembly.
  • CS8203: Invalid assembly name.

The following warning also indicates an invalid reference assembly:

  • CS1683: Reference to type 'Type Name' claims it is defined in this assembly, but it is not defined in source or any added modules

Check that the assembly name is spelled correctly. The referenced assembly file might be invalid.