ViShap.Viper.Generator
1.1.0-rc.1
Prefix Reserved
dotnet add package ViShap.Viper.Generator --version 1.1.0-rc.1
NuGet\Install-Package ViShap.Viper.Generator -Version 1.1.0-rc.1
<PackageReference Include="ViShap.Viper.Generator" Version="1.1.0-rc.1"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="ViShap.Viper.Generator" Version="1.1.0-rc.1" />
<PackageReference Include="ViShap.Viper.Generator"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add ViShap.Viper.Generator --version 1.1.0-rc.1
#r "nuget: ViShap.Viper.Generator, 1.1.0-rc.1"
#:package ViShap.Viper.Generator@1.1.0-rc.1
#addin nuget:?package=ViShap.Viper.Generator&version=1.1.0-rc.1&prerelease
#tool nuget:?package=ViShap.Viper.Generator&version=1.1.0-rc.1&prerelease
ViShap.Viper.Generator
The build-time source generator of Viper. It writes the
type contracts of a BinarySerializerContext, so the serializer reads and writes your types through
plain generated code instead of describing them by reflection on first use, and it reports every
contract mistake — a duplicate key, an unmarked member of a keyed contract, a delegate member — as a
compiler diagnostic instead of an exception at run time.
It runs only in the compiler. Nothing of it ships with your application, and a project with no
[BinaryContext] class gets nothing from it.
Use
using ViShap.Viper;
var serializer = new BinarySerializer(BinarySerializerOptions.Configure()
.WithContracts(AppContracts.Default)
.Build());
byte[] bytes = serializer.Serialize(new Order { Id = 7, Lines = [new Line { Sku = "A-1", Quantity = 2 }] });
Order? copy = serializer.Deserialize<Order>(bytes);
Console.WriteLine($"{copy!.Id}: {copy.Lines![0].Sku} x{copy.Lines[0].Quantity}"); // 7: A-1 x2
public sealed class Order
{
public int Id { get; set; }
public List<Line>? Lines { get; set; }
}
public sealed class Line
{
public string Sku { get; set; } = "";
public int Quantity { get; set; }
}
[BinaryContext(typeof(Order))]
public partial class AppContracts : BinarySerializerContext;
The context gets a contract for every type it lists and every member-encoded type those reach —
Line above, through the list. Each contract describes its type exactly as the serializer does by
reflection, so the bytes are the same with the context and without it, in both directions.
RequireGeneratedContracts() on the options turns a type the context lacks into an error instead of
a silent fallback to reflection.
The context also makes every type it reaches supported and exposes the type information of each type it
lists — AppContracts.Default.Order. The serializer's methods that take it build nothing by reflection
and carry no trimming or native AOT requirement, so an application published with native AOT
serializes through them.
Diagnostics
| Id | Severity | Meaning |
|---|---|---|
| VPR001 | Error | a [BinaryContext] class is not partial |
| VPR002 | Error | a [BinaryContext] class is not a non-generic, non-abstract class deriving from BinarySerializerContext |
| VPR003 | Error | a [BinaryContext] class declares a parameterless constructor or a Default member |
| VPR004 | Error | [BinaryKey] on a type that is not [BinaryContract] |
| VPR005 | Error | [BinaryInclude] together with [BinaryIgnore] |
| VPR006 | Error | two members share a [BinaryOrder] value |
| VPR007 | Error | [BinaryInclude] on a member of a contract type |
| VPR008 | Error | [BinaryOrder] on a member of a contract type |
| VPR009 | Error | [BinaryKey] together with [BinaryIgnore] |
| VPR010 | Error | a member of a contract type has neither [BinaryKey] nor [BinaryIgnore] |
| VPR011 | Error | a negative [BinaryKey] |
| VPR012 | Error | two members share a [BinaryKey] value |
| VPR013 | Error | a delegate member |
| VPR014 | Error | a member type with no representation on the wire (a pointer, a ref struct) |
| VPR015 | Error | a [BinaryUnion] tag outside 0–255 |
| VPR016 | Error | a [BinaryUnion] tag declared twice |
| VPR017 | Error | a [BinaryUnion] type not assignable to the base |
| VPR018 | Warning | an abstract type or interface without [BinaryUnion], whose values cannot be read back |
| VPR019 | Warning | a type that gets no generated contract and is described by reflection |
| VPR020 | Error | two listed types, or a listed type and a member of the context, share the name of a type information property |
| VPR021 | Error | a type that gets no generated contract, in an application that turns the reflection path off |
| VPR022 | Error | several constructors of a type marked [BinaryConstructor] |
| VPR023 | Error | a parameter of a [BinaryConstructor] constructor that names no member of exactly its type |
Each is explained, with its fix, in the generator documentation.
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on ViShap.Viper.Generator:
| Package | Downloads |
|---|---|
|
ViShap.Viper
Viper .NET binary engineering ecosystem meta-package. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.1.0-rc.1 | 59 | 11/17/2026 |
| 1.0.4 | 106 | 11/16/2026 |
| 1.0.3 | 97 | 11/16/2026 |
| 1.0.2 | 104 | 11/13/2026 |
| 1.0.1 | 117 | 10/27/2026 |
| 1.0.0 | 114 | 10/26/2026 |
| 1.0.0-rc.2 | 70 | 10/26/2026 |