0
votes

What append with this problem?

[A]SampleAzureWorker.DTO.SampleConfigScheduler cannot be cast to [B]SampleAzureWorker.DTO.SampleConfigScheduler. Type A originates from 'samplerestfull, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'LoadNeither' in a byte array. Type B originates from 'SampleAzureWorker, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'LoadNeither' in a byte array.

1
Please include the code showing how and what you're serializing so we'll have a better chance of helping. - krillgar
.Net serializers (especially BinaryFormatter) log the assembly (dll) name of the class being serialized. If the source dlls don't match (you have two classes with the same FQN, but from different assemblies), it will complain on deserialization. - sircodesalot
i'm using the DataContractSerializer.then I should implement another strategy serialization or there is a solution with DataContractSerialiezer class? - Roger Giuffre

1 Answers

0
votes

Are you trying to use a base type to pass your data back and forth?

Meaning I have a class called

[DataContract]
public class Data {}

[DataContract]
public class NetworkMessage 
{
    [DataMember]
    public Data MyData { get; set; }
}

[DataContract]
public class Foo : Data
{
    [DataMember]
    public int SomeId { get; set; }
}

[DataContract]
public class Bar : Data
{
    [DataMember]
    public string FirstName { get; set; }
}

If your WCF service is taking a NetoworkMessage then serialization will fail. You can fix this by using the KnownType attribute.

[DataContract]
[KnownType(typeof(Foo))]
[KnownType(typeof(Bar))]
public class Data {}

[DataContract]
public class NetworkMessage 
{
    [DataMember]
    public Data MyData { get; set; }
}

[DataContract]
public class Foo : Data
{
    [DataMember]
    public int SomeId { get; set; }
}

[DataContract]
public class Bar : Data
{
    [DataMember]
    public string FirstName { get; set; }
}