Appearance
Migrating from v15 to v16
v16 moves MemoryPack and Newtonsoft.Json support out of ActualLab.Core into separate packages, makes MessagePack the default binary serializer and RPC format, and replaces the process-wide RPC format registry with per-container wire format configuration.
The wire formats themselves don't change: mempack*, njson* and the persisted Newtonsoft.Json data are byte-for-byte the same as in v15, except for type-decorated payloads naming a type that moved to another assembly (see Upgrade Constraints). What changes is the defaults and how you opt in. Most apps only need Step 1 and Step 4.
What's New in v16
Serialization
- Lighter
ActualLab.Core. System.Text.Json and MessagePack are built in; MemoryPack, Newtonsoft.Json and Nerdbank.MessagePack support come from separate packages (ActualLab.Serialization.MemoryPack,.NewtonsoftJson,.NerdbankMessagePack). Core also no longer depends onUlid,System.Linq.Async,CommunityToolkit.HighPerformance,K4os.Compression.LZ4,Microsoft.Extensions.Hosting(only its abstractions) andMicrosoft.Extensions.Options.DataAnnotations– see Step 8. - MessagePack is the default binary serializer, and
msgpack6is the default RPC format (wasmempack6). - Nerdbank.MessagePack support is experimental, and MemoryPack is on its way out: it stays for compatibility with v15 peers, but gets no new features (e.g. no NativeAOT source generation support). Prefer MessagePack or System.Text.Json for new contracts.
- Newtonsoft.Json without attributes. ActualLab types carry only System.Text.Json and
[DataContract]attributes;NewtonsoftJsonContractResolvermaps them for Newtonsoft.Json (see Step 5). UniSerialized<T>and the type-decorating wrappers are plain wrappers serialized by whatever serializer is running, andIByteSerializer/ITextSerializergot scopedRead/Write(see Other Breaking Changes).
RPC
- Per-container wire formats. Each DI container configures its own format set, default format and backend-only formats with
RpcBuilder.ConfigureWireFormats(...); the process-wide registry is gone. The default set is slim, and everything else is opt-in (see Step 4). - Built-in LZ4 with preset dictionaries. LZ4 now lives in
ActualLab.Coreitself (a vendored copy of K4os.Compression.LZ4).ByteCodecis the codec: an immutable record of its settings plus an optional preset dictionary (DictionaryData), which it prepares once and shares with every encoder, so even the first frames after a compression context reset compress well.f.AddCompressedVariants(suffix, codec, mode)adds the compressed variants of the binary formats (see Dictionaries and Step 9). - Zstandard on .NET 11+.
ZstdByteCodecadds Zstandard frame compression, backed by .NET's own implementation, with the same preset dictionary support (see Zstandard). - Per-frame codec selection.
SelectingByteCodecpicks one of several codecs for each frame, e.g. LZ4 for small frames and Zstandard for large ones, and marks the frame with a 1-byte codec index (see Selecting a Codec per Frame). - Codec presets.
LZ4ByteCodec.HL16(64K hash slots, decodable by any LZ4 peer),ZstdByteCodec.Q3, andSelectingByteCodec.LZ4HL16_And_Zstd_At1K/LZ4HL16_And_ZstdQ3_At1K(LZ4 below 1 KB, Zstandard above; see Presets). - Keyed MessagePack.
f.AddKeyedMessagePack()addsmsgpack6k/msgpack6ck, which serialize your types as string-keyed maps instead of[Key(N)]arrays, so e.g. a TypeScript client reads them by member name (see Keyed MessagePack).
NativeAOT and Trimming
- Every serializer works under NativeAOT. The
NativeAotsample shows the built-in formats, andNativeAotFullevery serializer package, with one file per serializer listing what it needs. - Opt-in serialization roots. Define
ACTUALLAB_SERIALIZATION_ROOTSin an assembly, andActualLab.Generatorsroots the closed generic MessagePack formatters and System.Text.Json converters its contracts need, and checks its RPC contracts against itsJsonSerializerContexts (warningsALG0004,ALG0005;[assembly: IgnoreJsonCoverage(...)]excludes a type).ACTUALLAB_NO_PROXIESturns proxy generation off for an assembly that doesn't need it. - Source-generated System.Text.Json metadata. Add your
JsonSerializerContexttoSystemJsonSerializer.TypeInfoResolverbefore its types are first serialized. - No false-positive warnings. Registering Fusion services, compute methods, RPC clients or serializer packages no longer produces trimming / AOT warnings from ActualLab code.
See Native AOT and Trimming for the details.
Other Changes
Type.GetDefaultValue()returnsnullforNullable<T>(it returned the default ofT), which also fixes anullint?RPC argument arriving as0over the JSON formats.LZ4ByteDecoderreports malformed input withFormatException.- .NET Framework fixes:
TypeRefresolution of GAC and culture-specific assemblies,TickSourcewaiters,EncoderExt/DecoderExton empty input, and the NetFx RPC WebSocket server rejecting unsupported formats with close code 4001. RpcStreamno longer resends an item it can't serialize or deserialize forever: the stream fails.
Upgrade Constraints
- Hosts that share the operation log or backend RPC upgrade together.
IAuthBackend,IKeyValueStoreand their commands moved to another assembly, and the assembly name is part of the type name these commands are serialized with. - v15 clients default to
mempack6. To keep them working while you roll out v16, the server must serve it: addf.AddMemoryPack()there (see Step 4). - Moved type names only resolve forward. v16 reads payloads that name a moved type by its old assembly (
TypeRef.MovedTypes), but it writes the new name, which v15 can't resolve. This affects type-decorated payloads (e.g.PropertyBagvalues) that containApiOption,ApiNullable,ApiNullable8or the moved backend commands.
Step 1: Reference the packages you use
| If you use | Reference |
|---|---|
MemoryPackByteSerializer, MemoryPackSerialized<T>, [MemoryPackable] types with ActualLab members, mempack* RPC formats | ActualLab.Serialization.MemoryPack |
ApiOption<T>, ApiNullable<T>, ApiNullable8<T> | ActualLab.Serialization.MemoryPack |
NewtonsoftJsonSerializer, NewtonsoftJsonSerialized<T>, njson* RPC formats | ActualLab.Serialization.NewtonsoftJson |
nmsgpack* RPC formats | ActualLab.Serialization.NerdbankMessagePack |
OptionSet, ImmutableOptionSet, FuncByteSerializer, FuncTextSerializer (obsolete) | ActualLab.Core.Legacy |
IAuthBackend, IKeyValueStore and their commands without ActualLab.Fusion.Ext.Services | ActualLab.Fusion.Ext.Backend.Contracts |
FileSystemCache | ActualLab.Plugins |
ActualLab.Serialization.MemoryPack targets .NET Core 3.1+ and .NET Standard 2.1; it has no .NET Framework or .NET Standard 2.0 build.
The packages register their formatters, converters and SerializerKind entries from a module initializer when their assembly loads (on .NET 5+). If nothing in your app touches the package before the first serialization (e.g. you only use [MemoryPackable] types), or you target .NET Core 3.1 / .NET Standard 2.1, call MemoryPackSerialization.Register() / NewtonsoftJsonSerialization.Register() at startup.
ActualLab.Fusion.Ext.Services type-forwards IAuthBackend, IKeyValueStore and their commands, so code that uses them compiles unchanged.
Step 2: Fix MEMPACK019 in your [MemoryPackable] types
ActualLab types no longer carry [MemoryPackable]; the package serializes them with hand-written formatters registered at runtime. The MemoryPack source generator can't see those formatters, so a [MemoryPackable] type with a member like Session, Symbol, TypeRef, PropertyBag, Option<string>, Result<T> or User fails to compile with MEMPACK019. Add [MemoryPackAllowSerialize] to each such member:
cs
[DataContract, MessagePackObject, MemoryPackable(GenerateType.VersionTolerant)]
[method: System.Text.Json.Serialization.JsonConstructor, SerializationConstructor, MemoryPackConstructor]
public sealed partial record Note(
// ActualLab types: [MemoryPackAllowSerialize] is required since v16
[property: DataMember(Order = 0), Key(0), MemoryPackOrder(0), MemoryPackAllowSerialize] Session Session,
[property: DataMember(Order = 1), Key(1), MemoryPackOrder(1), MemoryPackAllowSerialize] Symbol Tag,
[property: DataMember(Order = 2), Key(2), MemoryPackOrder(2), MemoryPackAllowSerialize] Option<string> Title,
// Not needed for ApiArray/ApiList/ApiSet/ApiMap, unmanaged structs
// and ApiOption/ApiNullable over an unmanaged T
[property: DataMember(Order = 3), Key(3), MemoryPackOrder(3)] ApiArray<string> Lines,
[property: DataMember(Order = 4), Key(4), MemoryPackOrder(4)] ApiOption<int> Priority);You don't need it for ApiArray<T>, ApiList<T>, ApiSet<T>, ApiMap<TKey, TValue>, unmanaged structs (e.g. Moment, CpuTimestamp), and ApiOption<T> / ApiNullable<T> over an unmanaged T. Rebuild every assembly that declares such types: code the generator produced for v15 calls MemoryPack members ActualLab types no longer have.
If a [MemoryPackable] type of yours nests a generic ActualLab type inside another generic (e.g. a Dictionary<string, Option<MyStruct>> member), call MemoryPackSerialization.Register<T>() for that type at startup, so the nested type is serialized the same way as in v15.
Step 3: Drop MemoryPack and Newtonsoft.Json attributes you don't need
Your API records no longer need MemoryPack or Newtonsoft.Json attributes unless you use those serializers: [DataContract], MessagePack's [MessagePackObject] / [Key] and the System.Text.Json attributes are the baseline (see Annotating Types).
Step 4: Configure RPC formats per container
The default RPC format is now msgpack6 (was mempack6), and the default format set is slim: json5, json5np, msgpack5, msgpack5c, msgpack6, msgpack6c. Everything else – including the -lz4 variants – is opt-in via RpcBuilder.ConfigureWireFormats:
cs
services.AddRpc().ConfigureWireFormats(f => {
f.AddMemoryPack(); // ActualLab.Serialization.MemoryPack: mempack5(c), mempack6(c)
f.AddNewtonsoftJson(); // ActualLab.Serialization.NewtonsoftJson: njson5, njson5np
f.AddCompressedVariants("lz4", LZ4ByteCodec.Default); // "-lz4" variants of the formats added so far
f.DefaultFormat = f["msgpack6c-lz4"];
});- A client that pins a format (e.g.
f.DefaultFormat = f["msgpack6c-lz4"]) needs a server that serves it, so add the same formats on the server. RpcNerdbankSerializationFormat.Register()is gone; usef.AddNerdbankMessagePack().- RPC formats are now "wire formats":
RpcSerializationFormatbecameRpcWireFormat,RpcSerializationFormatResolverbecameRpcWireFormatResolver, andRpcHub.SerializationFormats,RpcPeer.SerializationFormatandRpcRef.SerializationFormatbecameWireFormats/WireFormat. - The built-in formats (
SystemJsonV5,MessagePackV6, ...) moved fromRpcSerializationFormattoRpcDefaultWireFormats; the package ones are inRpcMemoryPackWireFormats,RpcNewtonsoftJsonWireFormatsandRpcNerdbankWireFormats. RpcSerializationFormat.All,RpcSerializationFormat.Default,RpcSerializationFormatResolver.DefaultFormatsand the*_LZ4/*_LZ4Fformat statics are gone. Configure each container withrpc.ConfigureWireFormats(f => ...)instead:f.Add(...)/f.Remove(...),f.AddCompressedVariants("lz4", LZ4ByteCodec.Default),f.DefaultFormat(instead of assigningRpcSerializationFormatResolver.Default) andf.BackendOnlyFormatKeys(instead ofRpcSerializationFormatResolver.DefaultClientDeniedFormatKeys; the process-wide defaults are the read-onlyRpcDefaultWireFormats.DefaultFormatand.BackendOnlyFormatKeys).
See RPC Wire Formats for the builder API.
Step 5: Custom Newtonsoft.Json settings need NewtonsoftJsonContractResolver
ActualLab types no longer carry Newtonsoft.Json attributes or [JsonConverter]s. The default NewtonsoftJsonSerializer.DefaultSettings use NewtonsoftJsonContractResolver, which reads their System.Text.Json and [DataContract] attributes and supplies their converters. If you create JsonSerializerSettings yourself, set ContractResolver = new NewtonsoftJsonContractResolver() (or a subclass of it) – with the stock DefaultContractResolver, types like Symbol, Moment or Session serialize differently.
Persisted data written by Fusion (the EF operation log, the key-value store and auth data of ActualLab.Fusion.Ext.Services) still uses Newtonsoft.Json, in the same format as before; these packages reference ActualLab.Serialization.NewtonsoftJson themselves.
Step 6: Ulid needs its own MessagePack resolver
ActualLab.Core no longer references the Ulid and Ulid.MessagePack packages, and its MessagePack resolver no longer knows Ulid. UlidUuidGenerator still produces ULID strings without them.
- Code that used
Ulidthrough Core's reference must now reference theUlidpackage itself. - To send
Ulidwith MessagePack (the default RPC format ismsgpack6), referenceUlid.MessagePackand prepend its resolver at startup, before the firstUlidis serialized –DefaultMessagePackResolvercaches the formatter of each type on first use:
cs
// using ActualLab.Serialization.Internal; using Cysharp.Serialization.MessagePack;
DefaultMessagePackResolver.Resolvers = [UlidMessagePackResolver.Instance, .. DefaultMessagePackResolver.Resolvers];Without it, the first call that carries a Ulid fails with a MessagePack serialization error.
Step 7: ApiOption, ApiNullable and ApiNullable8 moved to ActualLab.Serialization.MemoryPack
These types exist only for MemoryPack contracts – see MemoryPack and Unmanaged Structs for why.
- Reference
ActualLab.Serialization.MemoryPackwherever you use them; namespaces are unchanged. The package has no .NET Framework / .NET Standard 2.0 build, so these types aren't available there anymore: useOption<T>/T?in contracts shared with such targets. Option<T>.ToApiOption()is now an extension method in that package, andOption<T>no longer implementsIConvertibleTo<ApiOption<T>>.ApiOption<T>.ToOption()is unchanged.ActualLab.Serialization.NerdbankMessagePackno longer has converters for them, so don't use them with thenmsgpack*formats. Before v16,ApiOption<T>was written as[]/[v], andApiNullable<T>/ApiNullable8<T>asnil/ the plain value.- Payloads that name them with their old assembly (
ActualLab.Core) still resolve viaTypeRef.MovedTypes.
Step 8: Reference the hosting packages you use
ActualLab.Core references Microsoft.Extensions.Hosting.Abstractions instead of Microsoft.Extensions.Hosting, and no longer references Microsoft.Extensions.Options.DataAnnotations. ASP.NET Core apps aren't affected: the shared framework includes all of them. Other apps (console, worker, desktop, test projects) that used these packages through Core now need their own references:
| If you use | Reference |
|---|---|
Host.CreateDefaultBuilder, HostBuilder, Host.CreateApplicationBuilder | Microsoft.Extensions.Hosting |
AddConsole(), AddDebug() and other logging providers | Microsoft.Extensions.Logging.Console, .Debug, ... |
| JSON / environment variable / command line configuration providers | Microsoft.Extensions.Configuration.Json, ... |
ValidateDataAnnotations() on options | Microsoft.Extensions.Options.DataAnnotations |
IHostedService, BackgroundService, IHostEnvironment, ILogger, IOptions<T> and configuration binding keep working without them.
Step 9: Compressed variants take a suffix and a ByteCodec
If you configured formats with 16.0.4 or earlier v16 builds: AddLZ4Variants and WithLZ4 are replaced with AddCompressedVariants and WithCompression, which take the suffix (used as is) and a ByteCodec, and adding a variant whose key already exists fails instead of keeping the existing format.
| Before | Now |
|---|---|
f.AddLZ4Variants() | f.AddCompressedVariants("lz4", LZ4ByteCodec.Default) |
f.AddLZ4Variants(RpcCompressionMode.Full) | f.AddCompressedVariants("lz4f", LZ4ByteCodec.Default, RpcCompressionMode.Full) |
f.AddLZ4Variants(filter, modes) | f.AddCompressedVariants(suffix, LZ4ByteCodec.Default, mode, filter), once per mode |
format.WithLZ4() | format.WithCompression("lz4", LZ4ByteCodec.Default) |
format.WithLZ4(RpcCompressionMode.Full) | format.WithCompression("lz4f", LZ4ByteCodec.Default, RpcCompressionMode.Full) |
format.WithCompression(key, compressionFormat, mode) | format.WithCompressionFormat(key, compressionFormat, mode) |
new RpcCompressionFormat(id, compressorFactory, decompressorFactory, options) | new RpcCompressionFormat(codec, options) |
ByteCompressor / ByteDecompressor | ByteEncoder / ByteDecoder (Compress / Decompress became Encode / Decode) |
new LZ4ByteCompressor(blockSize) / new LZ4ByteDecompressor(blockSize) | new LZ4ByteCodec { BlockSize = blockSize }.NewEncoder() / .NewDecoder() |
The keys stay the same (-lz4, -lz4f), so peers on either version still agree. A codec with a preset dictionary needs a suffix of its own, e.g. f.AddCompressedVariants("lz4d1", LZ4ByteCodec.Default with { DictionaryData = typicalFrames }).
Other Breaking Changes
- Serializer API.
IByteSerializer/ITextSerializerexposeReadUnscoped/WriteUnscoped;Read/Writebecame extension methods that open aByteSerializer.Scope. The asymmetric and converting byte/text serializers are gone. UniSerialized<T>andTypeDecoratingUniSerialized<TSchema, T>are plainValuewrappers: each format's converter serializesValuewith the serializer that is currently running (ByteSerializer.Current). Wire shapes are unchanged, except Nerdbank'sUniSerialized<T>, which goes from{"MessagePack": bin}to[bin].TSchema : TypeSchemaandTSanitizer : Sanitizertype parameters lost theirnew()constraint (PropertyBag<TSchema>,SanitizedString<TSanitizer>, the type-decorating wrappers). A customTypeSchemaorSanitizerstill needs a public parameterless constructor, but the compiler no longer checks it, and in trimmed apps the trimmer no longer keeps it: root it with a static constructor, e.g.static MySchema() => CodeKeeper.Keep<MySchema>();(see PropertyBag Serialization). Without it, a trimmed app fails withMissingMethodExceptionthe first time the type is used.- Moved type names.
TypeRef.MovedTypesmaps the names of types that moved to another assembly, so payloads written by v15 still resolve them. ActivatorExt.New<T>()is gone; useActivator.CreateInstance<T>().- Native AOT: the
MemoryPackByteSerializer.IsEnabledtrimming switch is gone – MemoryPack keep-code now exists only if you referenceActualLab.Serialization.MemoryPack. - Compression: a custom codec derives from
ByteCodec(an abstract record) and creates its encoders and decoders;RpcCompressionFormatwraps aByteCodecinstead of two factory delegates.RpcCompressionFormat.LZ4is unchanged.
Further Reading
- Unified Serialization – serializers, wrappers and the optional packages
- Native AOT and Trimming – serialization roots, source-generated JSON metadata
- RPC Wire Formats – the wire formats and their configuration
- NuGet Packages – what each package contains
- Changelog
