boltZharp Docs
hexagonSDKs

.NET apps

Zharp for .NET MAUI, WPF and Windows Forms: crashes sent on the next launch, hangs, screens and sessions, and release stacks with your files and lines, from one line at startup.

info
Zharp.Maui and Zharp.Windows 0.2.0

This SDK is new, and its API may still change before 1.0. Requires .NET 10 MAUI, or .NET 8+ / .NET Framework 4.6.2+ on Windows.

The same SDK as for .NET servers, with what apps on people's devices need — the way the Android, iOS and Flutter SDKs do it.

PackageFor
Zharp.Maui.NET MAUI on Android, iOS, Mac Catalyst and Windows (.NET 10).
Zharp.WindowsWPF and Windows Forms, and any other Windows desktop app (.NET 8+, .NET Framework 4.6.2+).
Zharp.BuildUploads each Release build's PDBs and sources, so release stacks read as your code.

Install and start

.NET MAUI

dotnet add package Zharp.Maui
dotnet add package Zharp.Build      # readable release stacks (below)
// MauiProgram.cs
var builder = MauiApp.CreateBuilder();
builder
    .UseMauiApp<App>()
    .UseZharp(o =>
    {
        o.Key = "zpk_…";
        o.Service = "shop-app";
        o.Environment = "production";
    });

WPF

dotnet add package Zharp.Windows
dotnet add package Zharp.Build      # readable release stacks (below)

First thing in App.OnStartup:

// App.xaml.cs
protected override void OnStartup(StartupEventArgs e)
{
    Zharp.ZharpApp.Start(o =>
    {
        o.Key = "zpk_…";
        o.Service = "shop-desktop";
        o.Environment = "production";
    });
    base.OnStartup(e);
}

Windows Forms and other desktop apps

First thing in Main. WPF and Windows Forms are recognised by themselves; in any other Windows desktop app, crashes, hangs, sessions and the offline queue work the same.

// Program.cs
[STAThread]
static void Main()
{
    Zharp.ZharpApp.Start(o =>
    {
        o.Key = "zpk_…";
        o.Service = "shop-desktop";
        o.Environment = "production";
    });
    ApplicationConfiguration.Initialize();
    Application.Run(new MainForm());
}

The key can also come from ZHARP_KEY in the environment.

What is recorded

  • Crashes. An exception nothing catches is written to the device first, then sent; when the app dies before it's sent, it goes the next time the app starts, with the session, user, screen and release it happened in. On MAUI that's Android's UnhandledExceptionRaiser, iOS's MarshalManagedException and WinUI's UnhandledException; on Windows, the AppDomain's unhandled exceptions.
  • Hangs. When the UI thread doesn't answer for 5 seconds, Zharp reports an ApplicationNotResponding error with the screen it happened on, once per freeze — not while a debugger is attached, and not for time a phone spent with the app in the background.
  • Screens. Each page (MAUI), window or page (WPF) and form (Windows Forms) shown records a screen CheckoutPage span and becomes screen.name on everything after it. Shell, navigation, tabbed and flyout pages are containers: what they show is the screen.
  • Sessions. session.id is on every span, log and error. A new session starts after 30 minutes in the background (or with no window of the app active, on Windows), and on ClearUser. An app started again sooner keeps its session.
  • A device ID (device.id), random and kept in the app's own storage, with the OS, its version and the device model.
  • Offline. What can't be sent waits on the device (up to 200 batches, 8 MB and three days, oldest dropped first) and goes once sending works again.
  • HTTP calls made with HttpClient are traced, as on servers.

Native crashes (iOS signals, the Android NDK, Windows access violations) aren't captured yet.

Errors

try
{
    await Checkout.PayAsync(cart);
}
catch (PaymentException e)
{
    Zharp.ZharpSdk.CaptureException(e);   // reported as handled, on this session and screen
}

WPF: exceptions your app handles

An exception your DispatcherUnhandledException handler handles (e.Handled = true) is reported as caught; one nothing handles ends the app and is reported as a crash.

Windows Forms: your own ThreadException handler

Windows Forms keeps one Application.ThreadException handler: the last one set wins. Zharp's reports the exception and then shows Windows Forms' usual dialog. If your app sets its own after ZharpApp.Start, report from it:

Application.ThreadException += (sender, e) =>
{
    Zharp.ZharpSdk.CaptureException(e.Exception, handled: false);
    // …your own handling
};

Readable stack traces

Apps ship without their PDBs, so a release build's frames have no file or line — and an app must never carry its source to its users. For each frame of your code without a line, the SDK sends the method's metadata token, the IL offset in it and the module's ID (its MVID). Zharp.Build uploads each Release build's portable PDBs and .cs files to Zharp under the same IDs, never into the app. Zharp then shows — and groups — errors by your methods, files and lines, with the code around each line, the way R8 mappings and dSYMs work.

<!-- your app's .csproj -->
<ItemGroup>
  <PackageReference Include="Zharp.Build" Version="0.2.0" PrivateAssets="all" />
</ItemGroup>
<PropertyGroup>
  <ZharpAppId>123</ZharpAppId>   <!-- the application's ID in Zharp; or ZHARP_APP_ID -->
</PropertyGroup>

Trimming (on by default for Android and iOS Release builds) rewrites the app's assemblies, so the trimmed copies are uploaded too, after ILLink runs. The upload needs a workspace API key with the artifacts:write scope in ZHARP_AUTH_TOKEN, set in CI — see The upload key:

# CI, on the Release build you ship
export ZHARP_AUTH_TOKEN=zak_…        # a workspace API key with the Build uploads scope
dotnet publish -c Release -f net10.0-android

Without a token the build only says what it would upload:

Zharp: dry run (no ZHARP_AUTH_TOKEN / ZharpAuthToken): would upload ShopApp.pdb as kind=portable-pdb debugId=561faf77-…, and 42 source file(s) as kind=source-bundle

ZHARP_URL (or <ZharpUrl>) points at another Zharp; <ZharpUploadSymbols>false</ZharpUploadSymbols> turns the upload off, and <ZharpUploadSources>false</ZharpUploadSources> keeps the sources out. The upload needs portable PDBs, the default — not <DebugType>none</DebugType> or full.

iOS: the method, not yet the exact line

iOS apps are compiled ahead of time, and their frames report no IL offset. Zharp still finds each frame's file and method from the PDB, and points at the method's first line rather than the line that threw. Android, Mac Catalyst and Windows frames get their exact line.

User context

Zharp.ZharpSdk.SetUser(user.Id, user.Email);   // once someone signs in
Zharp.ZharpSdk.ClearUser();                     // sign-out: a new session starts

Options

The same settings as on servers (Options), and three of apps' own, the second argument of UseZharp or ZharpApp.Start:

.UseZharp(o => o.Key = "zpk_…", app =>
{
    app.HangThreshold = TimeSpan.FromSeconds(3);   // default 5 s
    app.DetectHangs = true;
    app.TrackScreens = true;
});

To name a screen Zharp can't see:

Zharp.ZharpApp.SetScreen("Checkout");   // Zharp.Windows: a view swapped inside one window

Troubleshooting

Nothing arrives

On the app's setup page (Applications → the app → settings → Setup instructions), the verify step shows the first event as soon as it lands, and Send a test event checks the key on its own. If the test event arrives but your app's don't, the SDK isn't starting or isn't reaching Zharp:

  • Is init called, and before the code you expect to see? Without a key, the SDK starts nothing and says so once.
  • Does the service name match? With an app key everything goes to that app whatever it says; with a workspace key, service decides the app — see Keys.
  • Data is sent in batches every few seconds. A process that exits straight away should call flush first.
  • Logs and errors arrive but no traces? Check that tracing isn't turned off — see Logs only.
  • Is UseZharp (or ZharpApp.Start) reached before the first window, and is the key set? o.Debug = true prints what Zharp does to standard error.
  • A crash shows up the next time the app starts: open it again.

401 or 403

Ingest answers 401 when the key is missing, mistyped, revoked or rolled, and 403 when the request comes from an origin or IP address the key doesn't allow. Neither is retried: the SDK warns once and drops what was refused, and it never throws into your code. Copy the key again from the app's settings.

Release stacks still have no lines

  • Was the build you shipped the one Zharp.Build uploaded from (with ZHARP_AUTH_TOKEN set)? Its build output says so.
  • Is <DebugType> portable or embedded? Without a PDB there's nothing to read lines from.
  • Frames of the runtime and of libraries are left as they are: only your own code gets lines.
  • On iOS, frames point at the method's first line: see iOS.

Visual Basic apps

npm init zharp sets up C# projects. In a Visual Basic WPF or Windows Forms app, add the packages and the same call by hand: Zharp.ZharpApp.Start(Sub(o) o.Key = "zpk_…"), first in Application_Startup or Main.