ShockwaveFlash
Serialization

Diagnostics

The AVM1002-AVM1007 source-generator diagnostics catalog: causes and fixes.

The ShockwaveFlash.SourceGenerators source generator turns a partial class annotated with [Avm1Serializable(typeof(T), …)] into a reflection-free Avm1SerializerContext: a Default singleton, a lazily-built Avm1TypeInfo<T> per registered type, and a GetTypeInfo dispatch. When a registered type cannot be mapped it reports one of the diagnostics below instead of producing broken code.

All diagnostics are Error severity (the offending type is skipped) and belong to the Usage category. The IDs are a permanent contract: suppress one with #pragma warning disable AVM1002, an .editorconfig entry (dotnet_diagnostic.AVM1002.severity = none), or <NoWarn>AVM1002</NoWarn>.

IDTitle
AVM1002Unsupported member type
AVM1003No usable constructor
AVM1004Duplicate member key
AVM1005Containing type must be partial
AVM1006Unsupported declaration
AVM1007Context must be partial

AVM1002

Unsupported member type.

Member '{0}.{1}' has type '{2}' which the AVM1 serializer cannot map;
mark it with [Avm1Ignore], attach an [Avm1Converter], or use a supported type.

The member's type is not one of the supported member types — for example a pointer, a Dictionary<int, …> (only string keys are allowed), or an array of an unmappable element.

Fixes:

  • Use a supported type, or attach [Avm1Converter(typeof(MyConverter))] to own the mapping.
  • For genuinely dynamic data, type the member as Avm1Value, Avm1Array or Avm1Object to round-trip it verbatim.
  • Mark it [Avm1Ignore] if it should not be (de)serialized.
public partial record Quest(
    [property: Avm1Property("n")] string Name,
    [property: Avm1Property("r")] Avm1Array Rewards); // heterogeneous → pass-through

AVM1003

No usable constructor.

Type '{0}' has no accessible parameterless constructor and no single
constructor whose parameters all match (de)serialized members.

The context builds the instance either through a public parameterless constructor (then sets the init/set members) or by binding a single constructor's parameters to members by name. A type with only a multi-parameter constructor whose parameters do not all map to members cannot be built.

// positional record: the primary constructor binds to the members
public partial record Job(int Group, string Name, int Specialization);

// mutable type: parameterless ctor + init members
public partial class Settings
{
    public string? Theme { get; init; }
    public bool Mute { get; init; }
}

AVM1004

Duplicate member key.

Members '{1}' and '{2}' on type '{0}' both map to the AVM1 key '{3}'; keys must be unique.

Two members resolve to the same AVM1 key — usually because [Avm1Property("…")] collides with another member's name or attribute.

// AVM1004: both map to "n"
public partial record Bad(
    [property: Avm1Property("n")] string Name,
    string N);

// fixed
public partial record Good(
    [property: Avm1Property("n")] string Name,
    [property: Avm1Property("note")] string N);

AVM1005

Containing type must be partial.

Type '{0}' is nested in '{1}' which is not declared 'partial';
every containing type must be partial for generation to succeed.

The generated context is emitted inside its containing type(s), so each type that encloses the Avm1SerializerContext class must also be partial.

public partial class Catalog
{
    [Avm1Serializable(typeof(Entry))]
    public partial class Context : Avm1SerializerContext;
}

AVM1006

Unsupported declaration.

Type '{0}' cannot be made AVM1 serializable; generic types and ref-like types are not supported.

A registered type cannot be generic (Foo<T>) or ref-like (ref struct). Register a non-generic, non-ref type.

AVM1007

Context must be partial.

Context '{0}' is annotated with [Avm1Serializable] but is not declared 'partial';
the generator cannot complete the Avm1SerializerContext.

The generator completes the context in a second partial declaration (the Default singleton, constructors, accessors and GetTypeInfo), so the context class has to be partial.

// AVM1007
[Avm1Serializable(typeof(Emote))]
public class DemoContext : Avm1SerializerContext;

// fixed
[Avm1Serializable(typeof(Emote))]
public partial class DemoContext : Avm1SerializerContext;

On this page