06 March 2006
Issues Migrating from .NET 1.0 to .NET 1.1
Mainstream support for .NET 1.0
ends 30 June 2007. For organisations migrating from .NET 1.0 to .NET 1.1, the following changes are for consideration:
In addition to the changes listed above, the following issues were encountered during a recent migration activity.
Web Service WSDL Generation IssueAfter upgrading websites from ASP.NET 1.0 to 1.1, the following error message may be encountered:
The XML element named 'HelloWorldMethodResponse' from namespace 'http://www.test.com' references a method and a type. Change the method's message name using WebMethodAttribute or change the type's root element using the XmlRootAttribute.
This error occurs when the WSDL for a web service is being generated. Note that the error message includes two possible solutions. The first of these solutions which recommends changing the web methods message name using the WebMethodAttribute is undesirable as this will alter the WSDL contract and break existing consumers. The second of the two solutions, applying the XmlRoot attribute to the web methods return type, will resolve the error, however, this requires recompilation of existing web service assemblies.
Properties of web methods that cause this error include:
- The return type is a class or structure;
- The return type is named [WebMethodName]Response;
- The web method accepts no parameters (or has parameters that do not serialise to a complex type in the WSDL, for example, strings, integers).
This error does not affect the invocation of existing client proxies as they do not consume the WSDL at runtime. This issue will affect development activities when the WSDL is requested, for example, when re-generating client-side proxies using the Visual Studio Add/Update Web Reference feature.
To resolve this issue, apply the XmlRoot attribute to the return type of the WebMethod, noting the following:
- The ElementName should be of the form [ResponseType]Dummy. Note that no element named HelloWorldMethodResponseDummy will appear in the WSDL;
- The DataType property should be set to the response type.
An example application of the XmlRoot attribute is as follows:
[WebMethod(Description = "Test Method")]
[return: XmlRoot(Namespace = "http://www.test.com/",
ElementName = "HelloWorldMethodResponseDummy",
DataType = "HelloWorldMethodResponse",
IsNullable = false)]
public HelloWorldMethodResponse HelloWorldMethod()
{
return new HelloWorldMethodResponse();
}
Activator.CreateInstance() raises a System.MissingMethodException exception when creating instances of ArraysIn order for the Activator.CreateInstance() method to create instances of a given type, the type must define a public default constructor. In .NET 1.0, the Activator does not raise an exception when creating instances of Arrays (which has a private default constructor), however, this issue has been fixed for .NET 1.1 and now raises a System.MissingMethodException ("No parameterless constructor defined for this object") exception as expected.
To resolve this issue, the Array.CreateInstance() method can be used instead of Activator.CreateInstance(), as follows:
...
if (typeToInstantiate.IsArray)
{
Type elementType = typeToInstantiate.GetElementType();
newInstance = Array.CreateInstance(elementType, arraySize);
}
else
{
newInstance = Activator.CreateInstance(typeToInstantiate);
}