Table of Contents

AL0008: GetSchema must return null and not be abstract

GetSchema should return null according to IXmlSerializable guidance and should not be abstract.

When it triggers

public class MySerializable : IXmlSerializable
{
    // AL0008: IXmlSerializable.GetSchema should return null and not be abstract
    XmlSchema? IXmlSerializable.GetSchema() => new XmlSchema();
}

public abstract class BaseSerializable : IXmlSerializable
{
    // AL0008: GetSchema should not be abstract
    public abstract XmlSchema? GetSchema();
}

Why this matters

According to Microsoft's documentation, GetSchema should always return null. The schema should be provided via XmlSchemaProviderAttribute instead. Making it abstract forces derived classes to implement something that should always be null.

How to fix

Return null directly:

public class MySerializable : IXmlSerializable
{
    XmlSchema? IXmlSerializable.GetSchema() => null;
}

Configuration

[*.cs]
dotnet_diagnostic.AL0008.severity = warning