LsMsgPack.AspNetCore
2026.11.8.1
See the version list below for details.
dotnet add package LsMsgPack.AspNetCore --version 2026.11.8.1
NuGet\Install-Package LsMsgPack.AspNetCore -Version 2026.11.8.1
<PackageReference Include="LsMsgPack.AspNetCore" Version="2026.11.8.1" />
<PackageVersion Include="LsMsgPack.AspNetCore" Version="2026.11.8.1" />
<PackageReference Include="LsMsgPack.AspNetCore" />
paket add LsMsgPack.AspNetCore --version 2026.11.8.1
#r "nuget: LsMsgPack.AspNetCore, 2026.11.8.1"
#:package LsMsgPack.AspNetCore@2026.11.8.1
#addin nuget:?package=LsMsgPack.AspNetCore&version=2026.11.8.1
#tool nuget:?package=LsMsgPack.AspNetCore&version=2026.11.8.1
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 LtMsgPack, 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 LsMsgPack / LtMsgPack endpoints. |
To change the settings, pass a configuration action:
using LsMsgPack.TypeResolving.Types;
using LtMsgPack;
builder.Services.AddControllers()
.AddLsMsgPackSerializerFormatters(o =>
{
o.Plain = LtMsgPackPresets.MessagePackCSharp(); // or Nerdbank(); the default is Generic()
o.XLsMsgPack.TypeGuard = new AllowedTypesGuard().AllowAssemblyOf(typeof(Order));
});
With the code of LtMsgPack'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
- Web formatters: settings per media type, examples, schema negotiation
- Compatibility with other MsgPack libraries
- Security: request bodies from clients you don't trust
- Source and issues: github.com/mlsomers/LsMsgPack
| Product | Versions 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. |
-
.NETStandard 2.0
- LtMsgPack (>= 2026.11.8.1)
- Microsoft.AspNetCore.Mvc.Core (>= 2.3.13)
-
net8.0
- LtMsgPack (>= 2026.11.8.1)
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 |