I have this scenario where a webservice method I'm consuming in C# returns a Business object, when calling the webservice method with the following code I get the exception "Unable to cast object of type ContactInfo to type ContactInfo" in the reference.cs class of the web reference
Code:
ContactInfo contactInfo = new ContactInfo(); Contact contact = new Contact();
contactInfo = contact.Load(this.ContactID.Value); Any help would be much appreciated.
actually this is not a bug. its a problem with the version changes of your own project! because your final run don't use the original imported references on compile!
for example,
i was making a chat server, client. i used a packet structure to transmit data on client project. then imported the same reference to server project. when casting...
i got the same error.because the actual running reference at server project is not the reference now at client project! because i have rebuilt client project many times after!
in casting .... =()
always the new object need to be a newer or same version as the old object!
so what i did was, i build a separate project to create a dll for the Packet class and imported the dll file to both projects. if i did any change to Packet class, i have to import the reference to both client and server again.
I have this scenario where a webservice method I'm consuming in C# returns a Business object, when calling the webservice method with the following code I get the exception "Unable to cast object of type ContactInfo to type ContactInfo" in the reference.cs class of the web reference
ReplyDeleteCode:
ContactInfo contactInfo = new ContactInfo();
Contact contact = new Contact();
contactInfo = contact.Load(this.ContactID.Value);
Any help would be much appreciated.
actually this is not a bug. its a problem with the version changes of your own project! because your final run don't use the original imported references on compile!
ReplyDeletefor example,
i was making a chat server, client. i used a packet structure to transmit data on client project. then imported the same reference to server project. when casting...
Packet packet = (Packet)binaryFormatter.Deserialize(stream);
i got the same error.because the actual running reference at server project is not the reference now at client project! because i have rebuilt client project many times after!
in casting .... =()
always the new object need to be a newer or same version as the old object!
so what i did was, i build a separate project to create a dll for the Packet class and imported the dll file to both projects. if i did any change to Packet class, i have to import the reference to both client and server again.
then the casting wont give above exception!
regards!