Skip to main content

Explicit marshaling policies

Use JsMarshalAs on legal CLR slots when default conversion is insufficient. A policy belongs to the CLR signature; it is not a tag that bypasses validation on arbitrary JS values.

64-bit integers​

Int64/UInt64 default to number, which can lose precision outside JavaScript's safe-integer range. Opt in to exact BigInt:

using ZenTS;
public static class Ids
{
[return: JsMarshalAs(JsMarshalType.BigInt)]
public static long Echo([JsMarshalAs(JsMarshalType.BigInt)] long value) => value;
}
const Ids = CSharp['Assembly-CSharp']['Ids'];
Ids.Echo(9007199254740993n);

BigInt applies only to concrete long/ulong slots and legal byref elements, not enums, IntPtr, object, or whole long[] arrays.

Policies​

PolicyPurpose
Default / ObjectDefault or explicit CLR wrapper representation, validated by type
Bytesbyte[] ↔ copied Uint8Array
OpaqueValueBorrowed C#→JS call-scoped handle
TableStruct fields/properties named by Members
UnpackedValuesPositional struct members
ActualTypeUserDataRuntime-type view for legal reference return slots
BigIntExplicit Int64/UInt64 bigint

ActualTypeUserData is illegal on parameters, fields, types, declared string returns, or structs. Table uses e.g. Members = new[] { "X", "Y" }; optional input keys may end in ?, unlike UnpackedValues.

Configuration lifetime​

Attributes support legal parameter, return, field, property, and nongeneric class/struct positions. Generic member policies are validated after closing. AOT XML is not hot-reloadable; regenerate session/build tables after changes.

Legality, duplicate rules, and precedence are strict. An enum value existing does not make it applicable to every type. See MarshalAs.