android - System.ArgumentException: Value does not fall within the expected range C# when subscribing to event in a different class -


i'm developing android c# application using xamarin. has simple structure: mainactivity launches , creates instances of classes guihandler , connection. each class raises different events:

in connection.cs:

    public eventhandler<connectioneventargs> connectionmade;     protected virtual void onconnectionmade()     {         if (connectionmade != null) {             connectionmade (this, new connectioneventargs ());         }     }     public eventhandler<connectioneventargs> connectionfailed;     protected virtual void onconnectionfailed()     {         if (connectionfailed != null) {             connectionfailed (this, new connectioneventargs ());         }     }     public eventhandler<connectioneventargs> lostconnection;     protected virtual void onlostconnection()     {         if (lostconnection != null) {             lostconnection (this, new connectioneventargs ());         }     }     public eventhandler<connectioneventargs> receiveddata;     protected virtual void onreceiveddata(byte[] _bytedatareceived, int _bytedatareceivedlength)     {         if (receiveddata != null) {             receiveddata (this, new connectioneventargs {bytedatareceived = _bytedatareceived, bytedatareceivedlength = _bytedatareceivedlength});         }     }     public eventhandler<connectioneventargs> sentdata;     protected virtual void onsentdata()     {         if (sentdata != null) {             sentdata (this, new connectioneventargs ());         }     } 

in guihandler.cs:

    public eventhandler<guihandlereventargs> sendbuttonclicked;     protected virtual void onsendbuttonclicked()     {         if (sendbuttonclicked != null) {             sendbuttonclicked (this, new guihandlereventargs { sendtexteditdata = sendedittext.text });         }     } 

the subscriptions in mainactivity.cs file, gets run when application executed:

    ...     protected override void oncreate (bundle bundle)     {         base.oncreate (bundle);         setcontentview (resource.layout.main);          var guihandler = new guihandler();         var connection = new connection();          connection.connectionmade += guihandler.onconnectionmade;         connection.connectionfailed += guihandler.onconnectionfailed;         connection.lostconnection += guihandler.onlostconnection;         connection.receiveddata += guihandler.onreceiveddata;         connection.sentdata += guihandler.onsentdata;          // code below raises system.argumentexception: value not fall within expected range during runtime.         guihandler.sendbuttonclicked += connection.onsendbuttonclicked;         // however, line makes job.         guihandler.sendbuttonclicked += (sender, args) => connection.send (args.sendtexteditdata);     } 

i can't find reason why raises exception there , not anywhere else. however, doing debugging noticed can't subscribe public method connection, have no idea why. has idea?

edit: definition of onsendbuttonclicked in connection.cs:

    public void onsendbuttonclicked (object sender, guihandlereventargs args)     {         //send data         send(args.sendtexteditdata);     } 


Popular posts from this blog