LsMsgPack.AspNet.WebApi 2026.11.23.1

dotnet add package LsMsgPack.AspNet.WebApi --version 2026.11.23.1
                    
NuGet\Install-Package LsMsgPack.AspNet.WebApi -Version 2026.11.23.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.AspNet.WebApi" Version="2026.11.23.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LsMsgPack.AspNet.WebApi" Version="2026.11.23.1" />
                    
Directory.Packages.props
<PackageReference Include="LsMsgPack.AspNet.WebApi" />
                    
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.AspNet.WebApi --version 2026.11.23.1
                    
#r "nuget: LsMsgPack.AspNet.WebApi, 2026.11.23.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.AspNet.WebApi@2026.11.23.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.AspNet.WebApi&version=2026.11.23.1
                    
Install as a Cake Addin
#tool nuget:?package=LsMsgPack.AspNet.WebApi&version=2026.11.23.1
                    
Install as a Cake Tool

LsMsgPack.AspNet.WebApi

MsgPack MediaTypeFormatter for ASP.NET Web API 2 and for HttpClient (GetFromMsgPackAsync / PostAsMsgPackAsync, or ObjectContent / ReadAsAsync) on any platform. Serializing is done by LsMsgPack, which reads and writes several times faster than System.Text.Json.

It speaks the same formats as LsMsgPack.AspNetCore and LsMsgPack.AspNet.Mvc, so a client using this package can talk to a server using either of them.

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).

ASP.NET Web API 2

using LsMsgPackWebApiFormatters;

public static void Register(HttpConfiguration config)
{
  config.Formatters.Add(new LsMsgPackMediaTypeFormatter());
  config.MapHttpAttributeRoutes();
}

Web API's content negotiation handles the rest, based on the Content-Type and Accept headers. JSON stays the default.

HttpClient

using LsMsgPackWebApiFormatters;

// Once, for the lifetime of the app. The handler lets the server stop repeating schemas the client already has.
LsMsgPackMediaTypeFormatter formatter = new LsMsgPackMediaTypeFormatter();
HttpClient client = new HttpClient(formatter.CreateHandler()) { BaseAddress = new Uri("https://example.com/") };

// Per call
Order order = await client.GetFromMsgPackAsync<Order>("api/orders/42", formatter);
HttpResponseMessage response = await client.PostAsMsgPackAsync("api/orders", order, formatter); // also PutAsMsgPackAsync, PatchAsMsgPackAsync
await response.EnsureSuccessStatusCodeAsync();
Order saved = await response.Content.ReadFromMsgPackAsync<Order>(formatter);

The helpers ask for MsgPack (Accept: application/x-lsmsgpack, application/msgpack; q=0.9) unless the request or the client has an Accept header, and send the body as application/x-lsmsgpack. For another media type, use new ObjectContent<Order>(order, formatter, MsgPackMediaTypes.MsgPack) and response.Content.ReadAsAsync<Order>(new MediaTypeFormatter[] { formatter }) (details).

An error status code throws a MsgPackHttpException (an HttpRequestException) with what the body says: StatusCode, Text, and the Title, Detail and validation Errors of the problem details ASP.NET Core sends (application/problem+json, also when the request asks for MsgPack); ReadBody<T>(formatter) reads a MsgPack body (details).

Lists that the server streams (an ASP.NET Core action returning an IAsyncEnumerable<T>) are read as they arrive (.NET Standard 2.1: .NET Core 3.0 and up, MAUI...), and a server that doesn't stream sends the whole list, read the same way:

await foreach (Order order in client.GetFromMsgPackAsAsyncEnumerable<Order>("api/orders/export", formatter))
  Show(order);

client.GetMsgPackStreamAsync(url, formatter) returns a MsgPackStreamReader for anything else in a stream, and MsgPackStreamContent sends a request body that is a stream (details).

With IHttpClientFactory, add the handler without an inner handler (the factory sets it): services.AddHttpClient("api").AddHttpMessageHandler(() => formatter.CreateDelegatingHandler());, with the formatter as a singleton.

When your classes differ from the server's (other names or namespaces, e.g. an SDK with its own models), create the handler with formatter.CreateHandler(true): it asks for the described schema, by which the reader pairs your classes with the server's (details).

Settings are passed as new LsMsgPackMediaTypeFormatter(new LsMsgPackHttpOptions { ... }). In trimmed or AOT apps (e.g. iOS), use the code of LsMsgPack's source generator: new LsMsgPackMediaTypeFormatter(new LsMsgPackHttpSerializer(AppMsgPackContext.Default, options)) (the constructors without a context are marked [RequiresUnreferencedCode] and [RequiresDynamicCode], see Trimming and NativeAOT). With ReportDifferences = true, response.GetReadDifferences() (on the server Request.GetReadDifferences()) says what didn't match between the body and your classes, for example properties of another version of the models.

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 is compatible. 
.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 0 11/23/2026
2026.11.21.1 47 11/21/2026
2026.11.20.1 99 11/20/2026
2026.11.18.1 54 11/18/2026
2026.11.16.1 94 11/16/2026
2026.11.14.1 97 11/14/2026
2026.11.12.1 98 11/12/2026
2026.11.9.2 100 11/9/2026
2026.11.9.1 91 11/9/2026
2026.11.8.1 91 11/7/2026
2026.11.6.1 92 11/6/2026
2026.11.3.1 102 11/3/2026
2026.10.29.1 103 10/29/2026
2026.10.28.2 104 10/28/2026
2026.10.28.1 102 10/28/2026
2026.10.27.1 98 10/27/2026
2026.10.26.1 88 10/26/2026
2026.10.24.1 99 10/23/2026
2026.10.22.1 104 10/21/2026
2026.10.11.1 102 10/10/2026
Loading failed