ViShap.Viper.Generator 1.0.1

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package ViShap.Viper.Generator --version 1.0.1
                    
NuGet\Install-Package ViShap.Viper.Generator -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ViShap.Viper.Generator" Version="1.0.1">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ViShap.Viper.Generator" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="ViShap.Viper.Generator">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ViShap.Viper.Generator --version 1.0.1
                    
#r "nuget: ViShap.Viper.Generator, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ViShap.Viper.Generator@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ViShap.Viper.Generator&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=ViShap.Viper.Generator&version=1.0.1
                    
Install as a Cake Tool

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

Each is explained, with its fix, in the generator documentation.

There are no supported framework assets in this package.

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