Microsoft KB Archive/929545

From BetaArchive Wiki
Knowledge Base


Error message when you try to use a client application that is built on the .NET Framework 1.1 to consume a .NET Framework 2.0-based Web service: "System.InvalidOperationException"

Article ID: 929545

Article Last Modified on 12/21/2006



APPLIES TO

  • Microsoft .NET Framework 1.1
  • Microsoft Web Services Enhancements for Microsoft .NET 1.1



SYMPTOMS

When you try to use a Microsoft .NET Framework 1.1-based client to consume a Microsoft .NET Framework 2.0-based Web service, you may receive an error message that resembles the following:

System.InvalidOperationException: There is an error in XML document (1, 446). --->
System.FormatException: Input string was not in a correct format. at System.Number.ParseUInt32(String s, NumberStyles style, NumberFormatInfo info)
at System.Xml.XmlConvert.ToUInt32(String s)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderTestWs.Read1_Object1(Boolean isNullable, Boolean checkType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderTestWs.Read6_GetMethodResponse()
at Microsoft.Xml.Serialization.GeneratedAssembly. GetMethodResponseSerializer.Deserialize(XmlSerializationReader reader)
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)

This behavior may also occur when you use a Java-based client.

Note This behavior does not occur when you use a .NET Framework 2.0-based client.

CAUSE

This behavior occurs because the .NET Framework 1.1 does not support deserialization of nullable value types.

WORKAROUND

To work around this behavior, modify the proxy class for the client application to convert nullable value types to reference types. In the following example, the nullable int type is converted to the string type. When the string value is returned, the value is converted back to the int type.

For example, the code for the proxy class for the client application may resemble the following code example.

public class MyClass
{
  public int id;
}

To work around this problem, replace the code for the proxy class with the following code example.

public class MyClass
{
  [XmlElement(IsNullable = true)]
  public string id;

  [XmlIgnore]
  public int idValue
  {
    get
    {
      if (this.id == null || this.id.Length == 0)
        return 0;
      return Convert.ToInt32(id);
    }
    set
    {
      id = Convert.ToString(value);
    }
  }
}

Keywords: kbcode kbexcepthandling kbwebclasses kb80004005 kbwebservices kbexpertiseinter kbtshoot kbprb KB929545