Application Data Storage

Learn how to use built-in secure data storage in an MAUI app.

Any application type will need to store its data in some sort of storage. .NET MAUI applications are not an exception. We'll cover what storage options are available in .NET MAUI applications. We'll use the following project setup to provide us with some examples.

<?xml version = "1.0" encoding = "UTF-8" ?>
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:SecureStorageDemo"
             x:Class="SecureStorageDemo.App">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Resources/Styles/Colors.xaml" />
                <ResourceDictionary Source="Resources/Styles/Styles.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>
.NET MAUI project example with secure storage demonstration

Data storage supported by MAUI

Broadly speaking, there are three types of persistent data storage supported by MAUI:

Storage Type

Advantages

Disadvantages

File storage

  • Standard C# implementation
  • Easy to work with
  • Has issues with platform-specific permissions
  • May be difficult to implement in a cross-platform fashion

Database storage

  • Easy to store data in a cross-platform fashion
  • Requires third-party dependencies

Secure data storage

  • Easy to implement in a cross-platform fashion
  • Abstracts away platform-specific implementations
  • Limited to key-value pairs

There's also the ability to store data in memory. But we won't consider it as storage because the data does not persist once the application is closed and the memory is freed. There's also an ability to store data on the server. But again, we won't consider this, since the storage functionality isn't performed by the native application ... ...