c# - .NET remoting exception ArgumentOutOfRange -


i have .net smart card , using c# build card application , host application. smart card acts server in .net remoting.

in smart card, have remote object (myclass) , call remote method :

public int addperson (string name,string age) 

to add information object.

public class myclass : marshalbyrefobject {   private string text1; private string text2; private int noofperson = 0 ; private person[] list = new person [6];       public void settext1(string t)     { text1= t; }     public void settext2(string t)     { text2= t }              public string gettext1 ()     { return text1; }     public string gettext1 ()     { return text1; }      public int addperson (string name,string age)     {         person obj = new person ();         obj.name =  name;         obj.age =  age;        list[noofperson] = obj;         noofperson ++;         return noofperson - 1 ; //index of current person                    return 1 ;      }       public personstruct getpesrson(int index)     {         return personstruct.converttostruct(list[index]);      } } 

person class:

public class person {     private string name;     private string age;      public string age     {         { return age; }         set { age = value; }     }     public string name     {         { return name; }         set { name = value; }     }} 

personstruct:

  public struct personstruct     {      public string name;     public string age;      public static personstruct converttostruct(person obj)     {         personstruct tmp = new personstruct ();                     tmp.name = obj.name;         tmp.age = obj.age;         return tmp;         } 

to retrieve each element of person array, firstly convert struct because there problem when try serialize object. anyway method :

public personstruct getpesrson(int index) 

the problem raised in method, although stored in smart card. got argumentoutofrange exception these details:

message index , length must refer location within string.   targetsite:  void handlereturnmessage(system.runtime.remoting.messaging.imessage , system.runtime.remoting.messaging.imessage)  paramname: length  source: mscorlib  stacktrace: server stack trace:    @ system.string.internalsubstringwithchecks(int32 startindex, int32 length, boolean falwayscopy)    @ system.string.substring(int32 startindex, int32 length)    @ smartcard.runtime.remoting.a.a(type , string& , imessage )    @ smartcard.runtime.remoting.a.a(type , string& , imessage )    @ smartcard.runtime.remoting.a.a(type , string& , imessage )    @ smartcard.runtime.remoting.a.a(type , byte[] , imessage )    @ smartcard.runtime.remoting.a.a(type , stream , imessage )    @ smartcard.runtime.remoting.channels.apdu.apduclientformattersink.syncproce ssmessage(imessage msg)  exception rethrown @ [0]:    @ system.runtime.remoting.proxies.realproxy.handlereturnmessage(imessage req msg, imessage retmsg)    @ system.runtime.remoting.proxies.realproxy.privateinvoke(messagedata& msgda ta, int32 type)    @ medicalrecordapp.medicalrecord.getexamination(int32 index)    @ mycompany.myclientapp.myclient.main() in c:\documents , settings\user\my  documents\visual studio 2008\projects\client2\client2\myclient.cs:line 36 

it sounds using substring index doesn't exist in string. you'd need make sure string has enough characters before using index.

if new project have @ wcf instead of remoting, might find more suitable. microsoft has published following diagram:

wcf


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -