unoplatform/uno · error · ArgumentNullException

Value cannot be null. (Parameter 'storeContext')

Error message

Value cannot be null. (Parameter 'storeContext')

What it means

Thrown as ArgumentNullException by the StoreContextExtension constructor when the storeContext argument is null or cannot be cast to the Xamarin Google Play StoreContext type (the 'as' cast yields null for a wrong type). This add-in wraps the Google Play in-app review API and requires a valid StoreContext instance.

Source

Thrown at src/AddIns/Uno.UI.GooglePlay/StoreContextExtension.cs:28

using Android.OS;
using Android.Print;
using Uno.Foundation.Logging;
using Windows.Foundation.Metadata;
using Windows.Services.Store;
using Windows.Services.Store.Internal;
using Xamarin.Google.Android.Play.Core.Review;
using Xamarin.Google.Android.Play.Core.Review.Testing;
using Xamarin.Google.Android.Play.Core.Tasks;

namespace Uno.UI.GooglePlay;

public class StoreContextExtension : IStoreContextExtension
{
	private readonly StoreContext _storeContext;

	public StoreContextExtension(object storeContext)
	{
		_storeContext = storeContext as StoreContext ?? throw new ArgumentNullException(nameof(storeContext));
	}

	public async Task<StoreRateAndReviewResult> RequestRateAndReviewAsync(CancellationToken token)
	{
		TaskCompletionSource<StoreRateAndReviewResult>? inAppRateTcs;

		inAppRateTcs = new();

		using var reviewManager = WinRTFeatureConfiguration.StoreContext.TestMode
			? new FakeReviewManager(Application.Context)
			: ReviewManagerFactory.Create(Application.Context);

		using var request = reviewManager.RequestReviewFlow();

		using var listener = new InAppReviewListener(reviewManager, inAppRateTcs);
		request.AddOnCompleteListener(listener);

		return await inAppRateTcs.Task;

View on GitHub (pinned to 0418340488)

Solutions

  1. Obtain a valid StoreContext before constructing StoreContextExtension — check for null from the Google Play StoreContext API.
  2. Guard the constructor call: only create StoreContextExtension when StoreContext is non-null (e.g. device has Google Play Services).
  3. On emulators, use WinRTFeatureConfiguration.StoreContext.TestMode = true to route through FakeReviewManager.

Example fix

// before
var ext = new StoreContextExtension(storeContext); // storeContext is null → throws

// after
if (storeContext is StoreContext ctx)
{
    var ext = new StoreContextExtension(ctx);
}
else
{
    // device lacks Google Play Services — skip in-app review
}
Defensive patterns

Strategy: type-guard

Validate before calling

// Before constructing, verify storeContext is a valid StoreContext
if (storeContext is StoreContext ctx)
{
    var ext = new StoreContextExtension(ctx);
}

Type guard

// Type guard to ensure the argument is a valid StoreContext
static bool IsValidStoreContext(object obj) => obj is StoreContext;

Try / catch

try {
    var ext = new StoreContextExtension(storeContext);
} catch (ArgumentNullException ex) when (ex.ParamName == 'storeContext') {
    // Google Play StoreContext unavailable — skip in-app review
}

Prevention

When it happens

Trigger: The caller passes null to the StoreContextExtension constructor, or passes an object that is not a StoreContext (the 'as StoreContext' yields null). This happens when StoreContext.GetDefault or equivalent returned null on a device without Google Play services.

Common situations: Running on a device/emulator without Google Play Services (where StoreContext cannot be obtained); the managed StoreContext was not initialized before the extension was created; passing a mock/wrong-type object in tests.

Related errors


AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13). Data as JSON: /api/errors/1d4f9663d80fded2. Report an issue: GitHub.