This is because one of the ContactInfo objects is a web service proxy and is in a different namespace.
This is a known issue with asmx style web services. I used to implement an automatic shallow copy to get around it ( here as though, if I did it again, I would probably look at AutoMapper ).
For example, if you have an assembly with the following class:
MyProject.ContactInfo
and you return an instance of it from the web method:
public class DoSomethingService : System.Web.Services.WebService { public MyProject.ContactInfo GetContactInfo(int id) {
Then, when you add the web link to your client project, you actually get this:
MyClientProject.DoSomethingService.ContactInfo
This means that if in your client application you call a web service to get ContactInfo , you have this situation:
namespace MyClientProject { public class MyClientClass { public void AskWebServiceForContactInfo() { using (var service = new DoSomethingService()) { MyClientProject.DoSomethingService.ContactInfo contactInfo = service.GetContactInfo(1);
In this last line, I use the ShallowCopy class:
namespace MyClientProject { public class MyClientClass { public void AskWebServiceForContactInfo() { using (var service = new DoSomethingService()) { MyClientProject.DoSomethingService.ContactInfo contactInfo = service.GetContactInfo(1);
Note
This only works because the proxy class and the "real" class have exactly the same properties (one of them is generated by Visual Studio).
Neil barnwell
source share