Cross-PlatformComplete guide

.NET MAUI

.NET Multi-platform App UI (.NET MAUI) is the .NET framework for creating native mobile and desktop applications with C# and XAML from a shared project. This guide connects the programming model to production decisions, failure modes, security, testing, performance, deployment, and operations.

Overview

.NET MAUI provides a single project system, shared controls and layouts, data binding, handlers, app lifecycle APIs, and access to native device capabilities. Shared code targets Android, iOS, macOS through Mac Catalyst, and Windows through WinUI 3. Teams can build native XAML interfaces or host reusable Razor components locally through BlazorWebView, combining web UI reuse with native device access and store packaging. The central design goal is one cross-platform .NET application with native lifecycle, adaptive UI, local persistence, secure platform integration, and resilient synchronization. .NET MAUI shares UI and application code while platform projects, permissions, packaging, accessibility, lifecycle, and store policy remain platform-specific. Teams should begin with a concrete user outcome and quality-attribute scenario, choose the smallest architecture that satisfies it, and record the operational owner. Assuming permanent connectivity or identical platform behavior causes data loss, frozen UI, broken navigation, permission failures, and rejected releases. A production design therefore needs explicit limits, identity, cancellation, telemetry, evaluation, recovery, and a safe change path. The dedicated sample keeps external infrastructure optional so readers can inspect the governing mechanics locally, then maps those mechanics to the hosted services and controls required in a real environment.

What you will learn

  • Explain the purpose and boundaries of .NET MAUI without confusing the tool with the whole architecture.
  • Decide when .NET MAUI is appropriate and when a simpler design is safer.
  • Design the core contracts, ownership, data flow, and failure behavior for one cross-platform .NET application with native lifecycle, adaptive UI, local persistence, secure platform integration, and resilient synchronization.
  • Apply authentication, authorization, validation, privacy, and least privilege at every trust boundary.
  • Test normal behavior, negative paths, dependency failure, recovery, and operational signals.
  • Deploy incrementally with observable acceptance criteria, rollback, and accountable ownership.
  • Run and extend the dedicated .NET MAUI Offline Order Sync sample.

Prerequisites

  • .NET 10, C# async programming, dependency injection, configuration, and structured logging.
  • The domain and platform fundamentals referenced by .NET MAUI.
  • Basic security, testing, observability, and continuous-delivery concepts.
  • A .NET 10 SDK to run .NET MAUI Offline Order Sync; no paid cloud account is required for its default path.

When to use .NET MAUI

Good fit

  • Use .NET MAUI when one cross-platform .NET application with native lifecycle, adaptive UI, local persistence, secure platform integration, and resilient synchronization directly addresses a measured product or operational need.
  • Use it when a named team can own the contracts, data, deployment, telemetry, cost, and incident response.
  • Introduce it behind a narrow boundary and prove the riskiest assumption with a production-shaped experiment.

Choose another approach when

  • Avoid .NET MAUI when the same outcome is available through a smaller in-process or managed capability.
  • Do not adopt it only for résumé value, diagram symmetry, or a vendor checklist.
  • Do not proceed without a threat model, failure policy, observability, and an exit or rollback path.

Key concepts

Single project

One SDK-style project shares code, fonts, images, app metadata, and resources while multi-targeting native platforms.

Handlers

Cross-platform controls map through handlers to native platform views and can be customized globally or per control.

Native and hybrid UI

Use XAML and native controls, or host Razor components locally with BlazorWebView and share them with a Blazor web application through a Razor class library.

Platform integration

Cross-platform APIs cover sensors, connectivity, secure storage, files, and permissions, with direct native APIs available when required.

Offline-first state

Offline-first state is a first-class design concern for one cross-platform .NET application with native lifecycle, adaptive UI, local persistence, secure platform integration, and resilient synchronization.

Platform lifecycle and accessibility

Platform lifecycle and accessibility is a first-class design concern for one cross-platform .NET application with native lifecycle, adaptive UI, local persistence, secure platform integration, and resilient synchronization.

Architecture

Shared C# uses native XAML controls or locally hosted Razor components, while MAUI handlers and device services connect the application to each operating system.

Shared C# + UI
XAML or BlazorWebView
Handlers + device APIs
Native app package

Conceptual architecture · Adapt to your system context

Implementation walkthrough

Build the critical path deliberately, then verify its observable behavior.

  1. 01

  2. 02

  3. 03

  4. 04

  5. 05

  6. 06

  7. 07

Code example

A shared page can call a cross-platform device API while permission and platform details stay behind .NET MAUI abstractions.

MainPage.xaml.cs
public partial class MainPage : ContentPage
{
    public MainPage() => InitializeComponent();

    private async void OnLocateClicked(object sender, EventArgs e)
    {
        var permission = await Permissions.RequestAsync<Permissions.LocationWhenInUse>();
        if (permission != PermissionStatus.Granted)
            return;

        var location = await Geolocation.Default.GetLocationAsync(
            new GeolocationRequest(GeolocationAccuracy.Medium),
            CancellationToken.None);

        LocationLabel.Text = location is null
            ? "Location unavailable"
            : $"{location.Latitude:F4}, {location.Longitude:F4}";
    }
}

Testing strategy

Test .NET MAUI as a behavior and operational boundary, not only as a library call.

  • Unit-test deterministic policy, validation, mapping, and error classification.
  • Use contract tests for provider, protocol, platform, and downstream boundaries.
  • Run integration tests with realistic serialization, configuration, identity, cancellation, and dependency behavior.
  • Exercise the primary failure: Assuming permanent connectivity or identical platform behavior causes data loss, frozen UI, broken navigation, permission failures, and rejected releases.
  • Load-test representative and adversarial inputs while observing latency, errors, saturation, and cost.
  • Keep a versioned acceptance suite that protects behavior during dependency and configuration changes.

Security considerations

Treat .NET MAUI input, dependencies, credentials, output, and administrative controls as separate trust boundaries.

  • Authenticate the caller and workload; authorize the operation and resource at the system that performs it.
  • Validate type, size, count, format, tenant, and allowed values before expensive or consequential work.
  • Use short-lived identity and least privilege; keep secrets out of source, logs, prompts, packages, and client storage.
  • Classify data, minimize collection and retention, redact telemetry, encrypt in transit and at rest, and support deletion policy.
  • Require explicit approval and idempotency for external side effects; audit actor, intent, policy decision, and outcome.
  • Patch and inventory dependencies, pin trusted sources, scan artifacts, and restrict outbound destinations.

Performance and scalability

Optimize the end-to-end user outcome within downstream capacity and cost limits.

  • Measure p50, p95, p99, throughput, failures, saturation, queue time, payload size, and cost together.
  • Set end-to-end deadlines and propagate cancellation instead of stacking independent timeouts.
  • Bound concurrency, queues, retries, payloads, fan-out, and caches so overload cannot grow without limit.
  • Cache only when identity, freshness, privacy, invalidation, and failure semantics are explicit.
  • Batch or stream only when the workload and user latency target justify the complexity.
  • Capacity-test dependency degradation and recovery because retry and replay traffic often dominate peak load.

Deployment and operations

Promote an immutable, observable change through environments with compatibility and rollback evidence.

  • Keep environment configuration external, validated at startup, and free of long-lived credentials.
  • Provision dependencies, identity, network policy, dashboards, alerts, and budgets through reviewed automation.
  • Use additive contracts and mixed-version compatibility before removing old behavior.
  • Deploy with canary or staged exposure, health gates, graceful shutdown, and automated rollback signals.
  • Record version and configuration in telemetry; retain runbooks, ownership, recovery targets, and escalation paths.
  • Rehearse dependency loss, restore, credential rotation, region or device failure, and data recovery where applicable.

Common problems and fixes

The local sample works but production behavior differs

Likely cause: Provider, identity, network, limits, data, or configuration assumptions were hidden.

Fix: Compare effective configuration and correlated dependency telemetry, then reproduce the smallest differing boundary.

Latency rises sharply under load

Likely cause: Concurrency, fan-out, retries, queues, or a downstream quota is unbounded.

Fix: Inspect saturation and queue time, stop retry amplification, apply backpressure, and reduce work per request.

A request succeeds twice or creates duplicate effects

Likely cause: The caller retried after an ambiguous result and the operation was not idempotent.

Fix: Use a stable operation ID, persist the outcome with the effect, and return the recorded result on replay.

Sensitive information appears in telemetry

Likely cause: Raw inputs, outputs, headers, or exceptions were logged without classification and redaction.

Fix: Stop the leak, restrict and rotate access as needed, redact by default, and test the telemetry schema.

A dependency upgrade changes behavior

Likely cause: Application semantics depended on provider-specific defaults or an untested protocol detail.

Fix: Pin or roll back, compare release notes and contract traces, then update the acceptance suite before retrying.

Operators cannot explain a failed user outcome

Likely cause: Logs, metrics, traces, version, and business identifiers are not correlated.

Fix: Add end-to-end correlation and a dashboard that links the user journey to dependency and deployment signals.

Best practices

  • Keep business logic and application state in platform-neutral services and view models so they can be unit tested without a device.
  • Place reusable Razor components in a Razor class library when a Blazor Hybrid app and a Blazor Web App share UI, while isolating host-specific services behind interfaces.
  • Use handlers or platform folders for genuine native differences instead of scattering platform checks throughout shared code.
  • Profile startup, memory, rendering, and package size on release builds because debug and emulator behavior can be misleading.
  • Design local state and an idempotent sync queue before adding remote calls; expose pending, failed, and conflict states to the user.
  • Keep domain and synchronization logic independent of pages so it can be tested without device emulators.

Production checklist

  • The need for .NET MAUI, alternatives, owner, constraints, and exit criteria are recorded.
  • Contracts, data ownership, trust boundaries, limits, and compatibility policy are explicit.
  • Identity, least privilege, validation, privacy, redaction, audit, and side-effect approval are enforced.
  • Timeout, cancellation, retry, backpressure, idempotency, fallback, and recovery behavior are tested.
  • Logs, metrics, traces, cost, quality, business outcomes, dashboards, alerts, and runbooks identify version and owner.
  • Capacity, dependency failure, restore, rollback, credential rotation, and incident response are rehearsed.
  • Lifecycle, deprecation, data retention, dependency patching, and operational cost have named owners.

Common interview questions

Does .NET MAUI render one identical UI on every platform?

No. Shared MAUI controls are mapped to native platform controls through handlers, so behavior and appearance can retain platform conventions while sharing most UI code.

How does Blazor Hybrid differ from a hosted web app?

Blazor Hybrid renders Razor components in a BlazorWebView inside the native MAUI app, with UI assets packaged locally and direct access to .NET and device services; it does not require a browser-hosted WebAssembly application.

Why must iOS and macOS builds use a Mac?

Apple's native toolchain and signing infrastructure are required to compile and package those applications, even when development begins from another operating system.

What belongs in shared MAUI code?

View models, domain logic, validation, navigation contracts, and most UI can be shared; platform APIs and packaging remain behind platform-specific implementations.

How should offline conflicts be handled?

Use version metadata and explicit merge policy, preserve the local intent, and ask the user when the business rule cannot resolve safely.

Dedicated GitHub sample

Clone, run, test, and modify the focused implementation created for this guide.

Verified sample

.NET MAUI Offline Order Sync

A .NET 10 offline-order domain core suitable for a MAUI app, with a durable-style outbox, idempotent synchronization, retry state, and conflict visibility.

.NET 10.NET MAUI Offline Order Sync
dedicated-samplebatch-18dotnet-maui
Run
dotnet run --project src/MauiOfflineOrderSync
Test
dotnet run --project src/MauiOfflineOrderSync -- --self-test