Naviehs

Member
System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at System.Linq.Enumerable.WhereListIterator`1.MoveNext()
at Server.Mobiles.BaseFamiliar.OnHit(Mobile attacker, IDamageable defender) in C:\Users\Administrator\Desktop\ServUO\Scripts\Mobiles\Summons\BaseFamiliar.cs:line 245
at Server.Items.BaseWeapon.OnHit(Mobile attacker, IDamageable damageable, Double damageBonus) in C:\Users\Administrator\Desktop\ServUO\Scripts\Items\Equipment\Weapons\BaseWeapon.cs:line 3021
at Server.Items.BaseRanged.OnHit(Mobile attacker, IDamageable damageable, Double damageBonus) in C:\Users\Administrator\Desktop\ServUO\Scripts\Items\Equipment\Weapons\BaseRanged.cs:line 132
at Server.Items.BaseWeapon.OnHit(Mobile attacker, IDamageable damageable) in C:\Users\Administrator\Desktop\ServUO\Scripts\Items\Equipment\Weapons\BaseWeapon.cs:line 2214
at Server.Items.BaseRanged.OnSwing(Mobile attacker, IDamageable damageable) in C:\Users\Administrator\Desktop\ServUO\Scripts\Items\Equipment\Weapons\BaseRanged.cs:line 100
at Server.Mobile.CombatTimer.OnTick() in C:\ServUO2\Server\Mobile.cs:line 2078
at Server.Timer.Slice() in C:\ServUO2\Server\Timer.cs:line 409
at Server.Core.Main(String[] args) in C:\ServUO2\Server\Main.cs:line 673
Post automatically merged:

What could be the main cause of "Collection was modified; enumeration operation may not execute." ?
 
Try changing the OnHit method as follows:

C#:
        public static void OnHit(Mobile attacker, IDamageable defender)
        {
            BaseCreature check = (BaseCreature)SummonFamiliarSpell.Table[attacker];

            if (check != null && check is BaseFamiliar && check.Weapon != null && check.InRange(defender.Location, check.Weapon.MaxRange))
            {
                check.Weapon.OnSwing(check, defender);
            }

            if (attacker is PlayerMobile)
            {
                // ToList() will copy the collection, ensuring that changes to the Linq expression collection do not cause a crash
                foreach (var ts in ((PlayerMobile)attacker).AllFollowers.Where(
                    m => m is BaseTalismanSummon && m.InRange(defender.Location, m.Weapon.MaxRange)).ToList())
                {
                    ts.Weapon.OnSwing(ts, defender);
                }
            }
        }
 

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back