Under the condition that neither can reference each other, and no 3rd party reference of contracts; the only logical solution is to deal with it as a change in domain. You could use a DataContract and a DataContractSerialiser to help you.
public static string Serialize(object obj)
{
using (MemoryStream memoryStream = new MemoryStream())
{
DataContractSerializer serializer = new DataContractSerializer(obj.GetType());
serializer.WriteObject(memoryStream, obj);
return Encoding.UTF8.GetString(memoryStream.ToArray());
}
}
public static object Deserialize(string xml, Type toType)
{
using (MemoryStream memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(xml)))
{
XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader(memoryStream, Encoding.UTF8, new XmlDictionaryReaderQuotas(), null);
DataContractSerializer serializer = new DataContractSerializer(toType);
return serializer.ReadObject(reader);
}
}
here you have effectively the same object defined in (pretend) two libraries.. FooA and FooB
[DataContract(Name="Foo")]
public class FooA
{
[DataMember]
public int Value;
}
[DataContract(Name = "Foo")]
public class FooB
{
[DataMember]
public int Value;
}
static public void Main()
{
var fooA = new FooA() {Value = 42};
var serialised = Serialize(fooA);
// Cross domain
var fooB = (FooB) Deserialize(serialised, typeof(FooB));
Console.WriteLine(fooB.Value);
}
Look up Windows Communication Foundation
A data contract is a formal agreement between a service and a client that abstractly describes the data to be exchanged. That is, to communicate, the client and the service do not have to share the same types, only the same data contracts. A data contract precisely defines, for each parameter or return type, what data is serialized (turned into XML) to be exchanged.