Package/assembly validation error codes
This reference article lists all the error codes generated by package validation and assembly validation.
List of error codes
Diagnostic ID | Description | Recommended action |
---|---|---|
PKV001 | A compile-time asset for a compatible framework is missing. | Add the appropriate target framework to the project. |
PKV002 | A run-time asset for a compatible framework and runtime is missing. | Add the appropriate asset for corresponding runtime to the package. |
PKV003 | A run-time independent asset for a compatible framework is missing. | Add the appropriate run-time independent target framework to the project. |
PKV004 | A compatible run-time asset for a compile-time asset is missing. | Add the appropriate run-time asset to the package. |
PKV005 | A compatible run-time asset for a compile-time asset and a supported runtime identifier is missing. | Add the appropriate run-time asset to the package. |
PKV006 | The target framework is dropped in the latest version. | Add the appropriate target framework to the project. |
PKV007 | The target framework and runtime identifier pair is dropped in the latest version. | Add the appropriate target framework and RID to the project. |
CP0001 | A type, enum, record, or struct visible outside the assembly is missing in the compared assembly when required to be present. | Add the missing type to the assembly where it is missing. |
CP0002 | A member that is visible outside of the assembly is missing in the compared assembly when required to be present. | Add the missing member to the assembly where it is missing. |
CP0003 | Some part of the assembly identity (name, public key token, culture, retargetable attribute, or version) does not match on both sides of the comparison. | Update the assembly identity so that both sides match. |
CP0004 | A matching assembly was not found on one side of the comparison when creating the assembly mapping. | Make sure the missing assembly is added to the package. |
CP0005 | An abstract member was added to the right side of the comparison to an unsealed type. |
Remove the member or don't annotate it as abstract . |
CP0006 | A member was added to an interface without a default implementation. | If the target framework and language version support default implementations, add one, or just remove the member from the interface. |
CP0007 | A base type on the class hierarchy was removed from one of the compared sides. | Add the base type back. (A new base type can be introduced in the hierarchy if that's intended.) |
CP0008 | A base interface was removed from the interface hierarchy from one of the compared sides. | Add the interface back to the hierarchy. |
CP0009 | A type that was unsealed on one side was annotated as sealed on the other compared side. |
Remove the sealed annotation from the type. |
CP0010 | The underlying type of an enum changed from one side to the other. | Change the underlying type back to what it was previously. |
CP0011 | The value of a member in an enum changed from one side to the other. | Change the value of the member back to what it was previously. |
CP0012 | The virtual keyword was removed from a member that was previously virtual. |
Add the virtual keyword back to the member. |
CP0013 | The virtual keyword was added to a member that was previously not virtual. |
Remove the virtual keyword from the member. |
CP0014 | An attribute was removed from a member that previously had it. | Add the attribute back to the member. |
CP0015 | The arguments passed to an attribute changed from one side to the other. | Change the arguments to the attribute back to what they were previously. |
CP0016 | An attribute was added to a member that previously did not have it. | Remove the attribute from the member. |
CP0017 | The name of a method's parameter changed from one side to the other. | Change the parameter's name back to what it was previously. |
CP0018 | The sealed keyword was added to an interface member that was previously not sealed. |
Remove the sealed keyword from the interface member. |
CP0019 | The visibility of a member was reduced from one side to the other. | Change the member's visibility back to what it was previously. |
CP0020 | The visibility of a member was expanded from one side to the other. | Change the member's visibility back to what it was previously. |
CP1001 | A matching assembly could not be found in the search directories. (Not applicable for package validation, only when using API Compat directly.) | Provide the search directory when loading matching assemblies using AssemblySymbolLoader . |
CP1002 | A reference assembly was not found when loading the assemblies to compare in the resolved directories for the current target framework. | Include the directory path where that assembly can be found using the following MSBuild item: <PackageValidationReferencePath Include="<path>" TargetFramework="<tfm>" /> . |
CP1003 | There was no search directory provided for the target framework moniker that the package validation is running API Compat for. | Provide the search directory to find references for that target framework using the following MSBuild item: <PackageValidationReferencePath Include="<path>" TargetFramework="<tfm>" /> . |
How to suppress
You can suppress individual diagnostic IDs in either of the following ways:
- Via a suppression file.
- Via the
NoWarn
compiler flag.
Suppression file
To suppress compatibility errors for intentional changes, add a CompatibilitySuppressions.xml file to your project. Package validation and assembly validation use the same suppression file format.
You can generate this file automatically in one of two ways:
- By passing
/p:GenerateCompatibilitySuppressionFile=true
if you're packing the project from the command line. - By adding the following property to your project file:
<GenerateCompatibilitySuppressionFile>true</GenerateCompatibilitySuppressionFile>
.
The suppression file looks like this.
<?xml version="1.0" encoding="utf-8"?>
<Suppressions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:A.B.DoStringManipulation(System.String)</Target>
<Left>lib/netstandard2.0/A.dll</Left>
<Right>lib/net6.0/A.dll</Right>
<IsBaselineSuppression>false</IsBaselineSuppression>
</Suppression>
</Suppressions>
DiagnosticId
specifies the ID of the error to suppress.Target
specifies where in the code to suppress the diagnostic IDs.Left
specifies the left operand of an APICompat comparison.Right
specifies the right operand of an APICompat comparison.IsBaselineSuppression
specifies whether to apply the suppression to a baseline validation (true
) or not (false
).
NoWarn compiler option
You can also suppress individual diagnostic IDs via the NoWarn
compiler flag, either per package or globally.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
...
<!-- The following NoWarn suppresses PKV001 project-wide -->
<NoWarn>$(NoWarn);PKV001</NoWarn>
</PropertyGroup>
</Project>
Cộng tác với chúng tôi trên GitHub
Bạn có thể tìm thấy nguồn cho nội dung này trên GitHub, nơi bạn cũng có thể tạo và xem lại các vấn đề và yêu cầu kéo. Để biết thêm thông tin, hãy xem hướng dẫn dành cho người đóng góp của chúng tôi.