Skip to content

Preferences listing crashes with non-string types on Android #39

@Redth

Description

@Redth

Problem

When a preference is stored with a non-string type (e.g., int, bool, double) via POST /api/preferences/{key} with type: "int", the GET /api/preferences listing endpoint crashes on Android with:

java.lang.Integer cannot be cast to java.lang.String

This happens because HandlePreferencesList always reads values via Preferences.Get(key, (string?)null), but Android's SharedPreferences stores typed values natively and throws ClassCastException when you read an int as a string.

The crash causes all preferences to disappear from the listing, not just the non-string one, since the entire handler fails.

Root Cause

  • HandlePreferencesSet correctly stores typed values (int, bool, double, float, long, datetime)
  • HandlePreferencesList always reads back as string, which fails on Android
  • HandlePreferencesGet also defaults to string when no type query param is specified

Expected Behavior

Listing and getting preferences should auto-detect the stored type and return the value regardless of its type.

Platform

Android only (iOS/macOS/Windows store all MAUI Preferences as strings internally).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions