stride3d/stride · error · ArgumentException

The provided listener was not present in the Audio System.

Error message

The provided listener was not present in the Audio System.

What it means

AudioSystem.RemoveListener removes a registered AudioListenerComponent from the Listeners dictionary. If the listener was never added (or was already removed), the ContainsKey check fails and an ArgumentException is thrown, as documented by the method's exception attribute. It protects the audio engine's listener bookkeeping from inconsistent updates.

Solutions

  1. Ensure RemoveListener is only called for listeners previously added via AddListener (i.e. on live AudioListenerComponents).
  2. Fix double-destroy: guard component teardown so Dispose/removal runs only once.
  3. Check the audio system isn't already removed/dropping listeners before scene teardown removes them.
  4. If calling manually, check AudioSystem.Listeners.ContainsKey(listener) (or a public equivalent) before removal.

Example fix

// before
audioSystem.RemoveListener(listener); // may throw if not registered

// after
if (audioSystem.Listeners.ContainsKey(listener))
    audioSystem.RemoveListener(listener);
Defensive patterns

Strategy: try-catch

Validate before calling

// Only remove listeners that are still registered
if (audioSystem.Listeners.ContainsKey(listener))
    audioSystem.RemoveListener(listener);

Try / catch

try { audioSystem.RemoveListener(listener); }
catch (ArgumentException ex) when (ex.Message.Contains("not present in the Audio System")) { /* already removed; ignore */ }

Prevention

When it happens

Trigger: Calling RemoveListener (internal, invoked via AudioListenerComponent destruction/Dispose paths) with a listener not present in AudioSystem.Listeners — e.g. removing the same listener twice, or removing a listener that was never registered with AddListener, at AudioSystem.cs:104.

Common situations: An AudioListenerComponent being destroyed twice (double Dispose during scene teardown); removing a listener entity from a scene it was never added to; component lifecycle ordering issues where the audio system already dropped the listener.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/adccc8a8b449a72e. Report an issue: GitHub.

Appendix: source

Thrown at sources/engine/Stride.Engine/Audio/AudioSystem.cs:104

        /// </summary>
        /// <param name="listener">The listener to add to the audio system.</param>
        /// <remarks>Adding a listener already added as no effects.</remarks>
        internal void AddListener(AudioListenerComponent listener)
        {
            if (!Listeners.ContainsKey(listener))
                Listeners[listener] = null;
        }

        /// <summary>
        /// Remove a <see cref="AudioListenerComponent" /> from the Audio System.
        /// After this call sounds played via <see cref="AudioEmitterSoundController" />s will not be heard by this listener anymore.
        /// </summary>
        /// <param name="listener">The listener to remove from the audio system.</param>
        /// <exception cref="System.ArgumentException">The provided listener was not present in the Audio System.</exception>
        internal void RemoveListener(AudioListenerComponent listener)
        {
            if (!Listeners.ContainsKey(listener))
                throw new ArgumentException("The provided listener was not present in the Audio System.");

            Listeners.Remove(listener);
        }

        public override void Update(GameTime gameTime)
        {
            AudioEngine?.Update();
        }

        // called on dispose
        protected override void Destroy()
        {
            Game.Activated -= OnActivated;
            Game.Deactivated -= OnDeactivated;

            base.Destroy();

            lock (AudioEngineStaticLock)

View on GitHub (pinned to 96fad776d2)