1
Vote

ArgumentOutOfRangeException when changing RasConnectionWatcher.Handle

description

ArgumentOutOfRangeException
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

Here is stack-trace
  Module "DotRas.RasConnectionWatcher", line 49, in set_Handle
    Void set_Handle(DotRas.RasHandle)
  Module "DotRas.RasConnectionWatcher", line 16, in Restart
    Void Restart()
  Module "DotRas.RasConnectionWatcher", line 32, in StopRaisingEvents
    Void StopRaisingEvents()
  Module "System.Collections.Generic.List`1", line 9, in get_Item
    T get_Item(Int32)
  Module "System.ThrowHelper", line 24, in ThrowArgumentOutOfRangeException
    Void ThrowArgumentOutOfRangeException()
Update: it looks like race condition there.

comments

mogikanin wrote Nov 4, 2015 at 5:53 PM

And there is another wrong thing in this class.
If you'll check setter of EnableRaisingEvents, then you can see the next piece of code:
 if (!this.IsSuspended())
                    {
                        if (this._enableRaisingEvents)
                        {
                            this.StartRaisingEvents();
                        }
                        else
                        {
                            this.StopRaisingEvents();
                        }
                    }
i.e. StopRaisingEvents() should be called when (!this.IsSuspended() && !_enableRaisingEvents) == true
That is correct. But if you look inside StopRaisingEvents() then you can see that it logic will run only when
(!this.IsSuspended() && this.EnableRaisingEvents) is true :)

wrote Nov 27, 2015 at 7:45 AM