views:

54

answers:

2

We have just found we are getting “framing errors” (as reported by the WCF logs) when running our system on some customer test machine.

It all works ok on our development machines.

We have an abstract base class, with KnownType attributes for all its sub classes. One of it’s subclass is missing it’s DataContract attribute.

However it all worked on our test machine!

On the customers test machine, we got “framing error” showing up the WCF logs, this is not the error message I have seen in the past when missing a DataContract attribute, or a KnownType attribute.

I wish to get to the bottom of this, as we can no longer have confidence in our ability to test the system before giving it to the customer until we can make our machines behave the some as the customer’s machines.


Code that try to show what I am talking about, (not the real code)

    [DataContract()]
    [KnownType(typeof(SubClass1))]
    [KnownType(typeof(SubClass2))] 
    // other subclasses with data members
    public abstract class Base
    {
        [DataMember]
        public int LotsMoreItemsThenThisInRealLife;
    }

    /// <summary>
    /// This works on some machines (not not others) when passed to Contract::DoIt, 
    /// note the missing [DataContract()]
    /// </summary>
    public class SubClass1 : Base
    {
        // has no data members
    }

    /// <summary>
    /// This works in all cases when passed to Contract::DoIt
    /// </summary>
    [DataContract()]
    public class SubClass2 : Base
    {
        // has no data members
    }

    public interface IContract
    {
        void DoIt(Base[] items);
    }

    public static class MyProgram
    {
        public static IContract ConntectToServerOverWCF()
        {
            // lots of code ...
            return null;
        }

        public static void Startup()
        {
            IContract server = ConntectToServerOverWCF();

            // this works all of the time
            server.DoIt(new Base[]{new SubClass2(){LotsMoreItemsThenThisInRealLife=2}});

            // this works "in develperment" e.g. on our machines, but not on the customer's test machines! 
            server.DoIt(new Base[] { new SubClass1() { LotsMoreItemsThenThisInRealLife = 2 } });
        }
    }

Update I have been told the .net 3.5 SP1 is on all the machines, I yet to comfirm this for myself.

+1  A: 

Hi Ian,

We had a similar problem: A file was properly data contract deserializing on all our test machines. However, on one particular customer machine, it failed with the error "[ClassName] cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute".

Turns out that the cusotmer was running .NET Framework 3.0, whereas all our testing had been done on .NET Framework 3.5 SP1.

It seems that the behavior of the data contract serializer is different accross .NET Framework 3.0 and .NET Framework 3.5. On 3.5, if a class is XML serializable, then it is automatically data contract serializable also. However, that is not the case with .NET Framework 3.0 - the class has to be decorated with the [DataContract] attribute or the [Serializable] attribute.

Hope this helps!

Abhishek [email protected]

Abhishek
A: 

I believe the problem is that some of the machine did not have 3.5 SP1 on them.

Ian Ringrose