LsMsgPack.AspNetCore 2026.11.16.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package LsMsgPack.AspNetCore --version 2026.11.16.1
                    
NuGet\Install-Package LsMsgPack.AspNetCore -Version 2026.11.16.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="LsMsgPack.AspNetCore" Version="2026.11.16.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LsMsgPack.AspNetCore" Version="2026.11.16.1" />
                    
Directory.Packages.props
<PackageReference Include="LsMsgPack.AspNetCore" />
                    
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 LsMsgPack.AspNetCore --version 2026.11.16.1
                    
#r "nuget: LsMsgPack.AspNetCore, 2026.11.16.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 LsMsgPack.AspNetCore@2026.11.16.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=LsMsgPack.AspNetCore&version=2026.11.16.1
                    
Install as a Cake Addin
#tool nuget:?package=LsMsgPack.AspNetCore&version=2026.11.16.1
                    
Install as a Cake Tool

LsMsgPack.AspNetCore

MsgPack input and output formatters for ASP.NET Core MVC / Web API controllers, and results and bodies for minimal APIs. Controllers receive and return MsgPack the same way they handle JSON, without any changes. Serializing is done by LsMsgPack, which reads and writes several times faster than System.Text.Json.

Targets ASP.NET Core 2.x (netstandard2.0, also on .NET Framework) and ASP.NET Core 3.0 and up (net8.0).

Usage

using LsMsgPackFormatters;

builder.Services.AddControllers()
  .AddLsMsgPackSerializerFormatters();

Clients choose the format with the Content-Type and Accept headers. JSON stays the default for clients that don't ask for MsgPack.

Media type Format
application/msgpack, application/x-msgpack Plain MsgPack, readable by any MsgPack implementation: maps keyed by property names, every value, Guid and decimal as text, dates as timestamps (a DateTimeOffset loses its offset).
application/x-lsmsgpack The indexed schema with type ids: smaller, polymorphic, and with the schema sent only once per client. Use this between endpoints that use LsMsgPack (or LsMsgPackDebug).

To change the settings, pass a configuration action:

using LsMsgPack.TypeResolving.Types;
using LsMsgPack;

builder.Services.AddControllers()
  .AddLsMsgPackSerializerFormatters(o =>
  {
    o.Plain = LsMsgPackPresets.MessagePackCSharp(); // or Nerdbank(); the default is Generic()
    o.XLsMsgPack.TypeGuard = new AllowedTypesGuard().AllowAssemblyOf(typeof(Order));
  });

With the code of LsMsgPack's source generator, pass the context first: .AddLsMsgPackSerializerFormatters(AppMsgPackContext.Default, o => ...). The overloads without one are marked [RequiresUnreferencedCode] and [RequiresDynamicCode] (see Trimming and NativeAOT).

To find out what didn't match between request bodies and your classes (properties of another version of the models), set o.ReportDifferences = true: the differences are available as HttpContext.GetReadDifferences() and logged at the Debug level (as a warning with o.LogDifferencesAsWarning = true). For example, to tell the client why a value is missing:

if (order.Address == null)
  return BadRequest("Validation failed: address is required\r\n" + 
    // Don't do this if your schema should not be public knowledge!
    HttpContext.GetReadDifferences());

With response compression, add the MsgPack media types: the default list (ResponseCompressionDefaults.MimeTypes) has JSON but no MsgPack, so MsgPack would be sent uncompressed and several times larger than gzipped JSON. See Response compression.

builder.Services.AddResponseCompression(o =>
  o.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(MsgPackMediaTypes.All));

Minimal APIs

For minimal APIs (ASP.NET Core 8 and up), register the serializer and use MsgPackResults.MsgPack(value) (or Results.Extensions.MsgPack(value)) and MsgPackBody<T>:

using LsMsgPackFormatters;

builder.Services.AddLsMsgPack();

app.MapPost("/api/orders", (MsgPackBody<Order> order) => MsgPackResults.MsgPack(orders.Add(order.Value)));

They behave like a controller with the formatters: MsgPack when the client asks for it (Accept, Content-Type), JSON otherwise. See Minimal APIs.

On the client side, use LsMsgPack.AspNet.WebApi with HttpClient, or any MsgPack library for the plain media types.

Documentation

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2026.11.23.1 12 11/23/2026
2026.11.21.1 48 11/21/2026
2026.11.20.1 100 11/20/2026
2026.11.18.1 53 11/18/2026
2026.11.16.1 100 11/16/2026
2026.11.14.1 102 11/14/2026
2026.11.12.1 90 11/12/2026
2026.11.9.2 105 11/9/2026
2026.11.9.1 100 11/9/2026
2026.11.8.1 93 11/7/2026
2026.11.6.1 96 11/6/2026
2026.11.3.1 104 11/3/2026
2026.10.29.1 99 10/29/2026
2026.10.28.2 107 10/28/2026
2026.10.28.1 105 10/28/2026
2026.10.27.1 104 10/27/2026
2026.10.26.1 95 10/26/2026
2026.10.24.1 109 10/23/2026
2026.10.22.1 106 10/21/2026
2026.10.11.1 105 10/10/2026
Loading failed