stride3d/stride · error · ArgumentException

The provided Sound is not currently attached to this…

Error message

The provided Sound is not currently attached to this emitter component.

What it means

AudioEmitterComponent.DetachSound throws ArgumentException when the given sound has no controller registered in this emitter's SoundToController map, i.e. it was never attached (or was already detached). Detaching works only on sounds previously passed to AttachSound on the same component.

Solutions

  1. Guard with SoundToController.ContainsKey(sound) (or the public equivalent check) before detaching.
  2. Only detach sounds you attached on this exact component instance; track attached sounds yourself.
  3. Wrap in try/catch for ArgumentException if detach-on-teardown may run twice.

Example fix

// before
emitter.DetachSound(sound); // throws if never attached
// after
if (emitter.Controllers.Any(c => c.Sound == sound))
    emitter.DetachSound(sound);
Defensive patterns

Strategy: try-catch

Validate before calling

if (emitter.Controllers.Any(c => c.Sound == sound))
    emitter.DetachSound(sound);

Try / catch

try { emitter.DetachSound(sound); }
catch (ArgumentException) { /* never attached or already detached; safe to ignore */ }

Prevention

When it happens

Trigger: Calling DetachSound with a sound attached to a different emitter, detaching twice, or detaching a sound that was removed via the Sound collection before DetachSound ran.

Common situations: Component teardown code detaching sounds already cleaned up, entity hierarchy changes removing sounds automatically (SoundRemoved), or confusion between two AudioEmitterComponents on different entities.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at sources/engine/Stride.Engine/Engine/AudioEmitterComponent.cs:164

            var newController = new AudioEmitterSoundController(this, sound);
            SoundToController[sound] = newController;
            ControllerCollectionChanged?.Invoke(this, new ControllerCollectionChangedEventArgs(Entity, newController, this, NotifyCollectionChangedAction.Add));

            return newController;
        }

        /// <summary>
        /// Detach a <see cref="SoundBase"/> from this emitter component.
        /// Once detach the controller previously associated to the SoundBase is invalid.
        /// </summary>
        /// <param name="sound">The SoundBase to detach.</param>
        /// <exception cref="ArgumentNullException">The provided <paramref name="sound"/> is null.</exception>
        /// <exception cref="ArgumentException">The provided <paramref name="sound"/> is not currently attached to the emitter component.</exception>
        public void DetachSound([NotNull] SoundBase sound)
        {
            if (sound == null) throw new ArgumentNullException(nameof(sound));
            if (!SoundToController.ContainsKey(sound))
                throw new ArgumentException("The provided Sound is not currently attached to this emitter component.");

            var oldController = SoundToController[sound];
            SoundToController.Remove(sound);
            ControllerCollectionChanged?.Invoke(this, new ControllerCollectionChangedEventArgs(Entity, oldController, this, NotifyCollectionChangedAction.Remove));
        }

        private void SoundAdded(SoundBase sound)
        {
            AttachSound(sound);
            SoundMultiplicities.TryGetValue(sound, out var v);
            SoundMultiplicities[sound] = v+1;
        }

        private void SoundRemoved(SoundBase sound)
        {
            var val = SoundMultiplicities[sound];
            if (val == 1)
            {

View on GitHub (pinned to 96fad776d2)