Friday, September 9, 2011

Adventures In Web Service and Remoting Server Craziness

I don't think there are that many people out there that still have to deal with more than one .Net Framework, but I have to deal with 3 simultaneously constantly. That means I use 3 different versions of Visual Studio simultaneously. The best part is everything I have to deal with has to talk to each other.

On to the topic at hand though. I learned a valuable and obscure lesson about getting a Remoting Server that is written in .Net v4.0 to send a custom object to a Web Service written in .Net v1.1.

All of the finer details aside here is the lesson I learned. If you are going to make a higher version of .Net - anything greater than v1.1 - then you need to make sure that you write the class in .Net v1.1. I am not referring to unsupported objects or technology such as Linq, I am referring to unsupported structure.

So for example if you get an error like so:
"...<PropertyName> k__backingfield were not found."

There is a good possibility that you might have tried to use a structure that isn't backwards compatible with .Net v1.1 and here is an example why:


//.Net v4.0 Side
[Serializable]
public class SerializableTestObject
{
    public SerializableTestObject()
    { 
    
    }

    [XmlElement]
    public bool BoolField { get; set; }
     
    [XmlElement]
    public bool StringField { get; }
}

Versus
//.Net v1.1 Side
[Serializable]
public class SerializableTestObject
{
    public SerializableTestObject()
    { 
    
    }

    private bool _boolField;
    [XmlElement]
    public bool BoolField { get {return _boolField; } set { _boolField = value; } }
     
    private string _stringField;
    [XmlElement]
    public bool StringField { get { return _stringField; } }
}

Even though those classes are technically identical, the difference is that .Net v1.1 doesn't understand what get; or set; means. That was introduced in .Net v3.0, so you will get the weird error described above if you try to pass the .Net v4.0 class version to the .Net v1.1 class version.

No comments:

Post a Comment