stride3d/stride · error · ArgumentException
The given IViewModelServiceProvider instance does not…
Error message
The given IViewModelServiceProvider instance does not contain an service implementing IUndoRedoService.
What it means
EditableViewModel depends on an IUndoRedoService (for transactions and dirty-state management) in addition to the base services. The constructor validates the service provider up front and throws ArgumentException if one cannot be resolved, giving a clear message instead of a later NullReferenceException.
Solutions
- Register an IUndoRedoService implementation in the provider before constructing the view model
- Use the standard ViewModelServiceProvider helper that wires the default undo/redo service
- In tests, add a mock/stub UndoRedoService to the provider
- Verify with serviceProvider.TryGet<IUndoRedoService>() before constructing
Example fix
// before var provider = new ViewModelServiceProvider(new DispatcherService(dispatcher)); var vm = new MyEditableViewModel(provider); // throws // after var provider = new ViewModelServiceProvider(new DispatcherService(dispatcher), new UndoRedoService()); var vm = new MyEditableViewModel(provider);
Defensive patterns
Strategy: validation
Validate before calling
if (serviceProvider.TryGet<IUndoRedoService>() == null)
throw new ArgumentException("Provider must include an IUndoRedoService before constructing an EditableViewModel."); Type guard
static bool HasUndoRedo(IViewModelServiceProvider p) => p.TryGet<IUndoRedoService>() != null;
Try / catch
try { vm = new MyEditableViewModel(provider); }
catch (ArgumentException ex) when (ex.Message.Contains(nameof(IUndoRedoService))) { /* fix provider wiring */ } Prevention
- Always register an IUndoRedoService in the provider used for EditableViewModel descendants
- In tests, include a stub UndoRedoService in the provider
- Construct providers via the standard factory that wires default services
When it happens
Trigger: Constructing a concrete EditableViewModel with an IViewModelServiceProvider that was not registered with an IUndoRedoService implementation (e.g. a minimal service provider or a mock missing the undo/redo service).
Common situations: Unit tests building a provider with only a dispatcher service; wiring view models before registering undo/redo services; replacing UndoRedoService with a stub that is not registered under the IUndoRedoService interface.
Understand the failure class
Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.
Related errors
- ArgumentNullException: dependencyManager
- A transaction failed to be created.
- Cannot register a service on a NullServiceProvider.
- Cannot unregister a service on a NullServiceProvider.
- No service matches the given type.
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/12af0af06c2389f0.
Report an issue: GitHub.
Appendix: source
Thrown at sources/presentation/Stride.Core.Presentation/ViewModels/EditableViewModel.cs:29
using Stride.Core.Presentation.Dirtiables;
namespace Stride.Core.Presentation.ViewModels;
public abstract class EditableViewModel : DispatcherViewModel
{
private readonly Dictionary<string, object?> preEditValues = [];
private readonly HashSet<string> uncancellableChanges = [];
private readonly List<string> suspendedCollections = [];
/// <summary>
/// Initializes a new instance of the <see cref="EditableViewModel"/> class.
/// </summary>
/// <param name="serviceProvider">A service provider that can provide a <see cref="IDispatcherService"/> and an <see cref="IUndoRedoService"/> to use for this view model.</param>
protected EditableViewModel(IViewModelServiceProvider serviceProvider)
: base(serviceProvider)
{
if (serviceProvider.TryGet<IUndoRedoService>() == null)
throw new ArgumentException($"The given {nameof(IViewModelServiceProvider)} instance does not contain an service implementing {nameof(IUndoRedoService)}.");
}
public abstract IEnumerable<IDirtiable> Dirtiables { get; }
/// <summary>
/// Gets the undo/redo service used by this view model.
/// </summary>
public IUndoRedoService UndoRedoService => ServiceProvider.Get<IUndoRedoService>();
protected void RegisterMemberCollectionForActionStack(string name, INotifyCollectionChanged collection)
{
ArgumentNullException.ThrowIfNull(collection);
collection.CollectionChanged += (sender, e) => CollectionChanged(sender, e, name);
}
protected IDisposable SuspendNotificationForCollectionChange(string name)
{View on GitHub (pinned to 96fad776d2)