I created 3 projects: class library (referenced by two following), web service and client application. When in client application I try to get an object of "shared type" from web service I get an error Cannot implicitly convert type 'ClientProject.ServiceProject.AB' to 'ClassLibrary.AB'
. I thought that this is problem with how I used DataContract but I tried several approaches and it still gives the same result. Could you please give me some directions what do I do wrong?
Class library AB class:
using System;
using System.Runtime.Serialization;
namespace ClassLibrary
{
[Serializable]
[DataContract(Name = "AB", Namespace = "ClassLibrary")]
public class AB
{
[DataMember(Name = "a")]
private int a;
[DataMember(Name = "b")]
private byte[] b;
<some_more_methods_here>
}
}
Web service method:
using ClassLibrary;
[...]
[WebMethod]
public AB calledMethod(byte[] x)
{
int a = [...]
byte[] b = [...]
AB ab = new AB(a, b);
return ab;
}
Failing client code:
using ClassLibrary;
[...]
byte[] x = [...]
var serviceProjectSoapClient = new ServiceProject.ServiceProjectSoapClient();
AB ab = new AB();
ab = serviceProjectSoapClient.calledMethod(x);
Edit:
As there were some concerns about whether I used shared project or Class library here's some clarification.
I tried the following: 1) created "Class Library" project; 2) built it; 3) referenced it's *.dll from both server and client application (both point to exactly the same *.dll file in the same location and when I inspect the type in both project both show me exactly the same from metadata).