Nóta
Aðgangur að þessari síðu krefst heimildar. Þú getur prófað aðskrá þig inn eða breyta skráasöfnum.
Aðgangur að þessari síðu krefst heimildar. Þú getur prófað að breyta skráasöfnum.
Cause
A project has <VerifyReferenceAotCompatibility>true</VerifyReferenceAotCompatibility> set, and one or more referenced assemblies don't have the IsAotCompatible assembly metadata attribute set to true.
Rule description
When you publish with Native AOT using <PublishAot>true</PublishAot> or mark your project as AOT-compatible with <IsAotCompatible>true</IsAotCompatible>, you can optionally enable verification that all referenced assemblies are also annotated for AOT compatibility. This helps ensure that all dependencies in your project are annotated for AOT compatibility.
To enable this verification, set the VerifyReferenceAotCompatibility property to true in your project file:
<PropertyGroup>
<PublishAot>true</PublishAot>
<VerifyReferenceAotCompatibility>true</VerifyReferenceAotCompatibility>
</PropertyGroup>
When this property is enabled, the analyzer checks that all referenced assemblies have been built with <IsAotCompatible>true</IsAotCompatible>, which adds the assembly-level attribute [assembly: AssemblyMetadata("IsAotCompatible", "True")] to the assembly.
Example
// Assembly reference: MyLibrary.dll (built without <IsAotCompatible>true</IsAotCompatible>)
public class Program
{
public static void Main()
{
var obj = new MyLibrary.SomeClass();
}
}
warning IL3058: Referenced assembly 'MyLibrary' is not built with `<IsAotCompatible>true</IsAotCompatible>` and may not be compatible with AOT.
How to fix violations
You have several options to fix this warning:
- If you control the library source code, update the referenced library to be built with
<IsAotCompatible>true</IsAotCompatible>. TheIsAotCompatibleproperty marks the assembly as compatible with Native AOT and enables AOT-specific analysis. This is the preferred approach. - If you're confident that the library works correctly with Native AOT even without the attribute, disable the verification by setting
<VerifyReferenceAotCompatibility>false</VerifyReferenceAotCompatibility>in your project file.