BUG: "Cannot implicitly convert type 'System.Data.DataSet'" error when application is built (815131)
The information in this article applies to:
- Microsoft Visual C# .NET (2003)
- Microsoft Visual C# .NET (2002)
- Microsoft Visual Basic .NET (2003)
- Microsoft Visual Basic .NET (2002)
- Microsoft XML Classes (included with the .NET Framework 1.0)
- Microsoft XML Classes (included with the .NET Framework 1.1)
Beta Information This article discusses a Beta release of a Microsoft
product. The information in this article is provided as-is and is subject to
change without notice.
No formal product support is available from
Microsoft for this Beta product. For information about how to obtain support
for a Beta release, see the documentation that is included with the Beta
product files, or check the Web location from which you downloaded the release.
SYMPTOMSYou have a Web Service that has a Web Service method that returns an instance of a custom class. The class that
is returned by the Web Service method implements the IXmlSerializable interface. If you use this Web Service in an application, you may
receive the following error message when you build the application:
Cannot implicitly convert type 'System.Data.DataSet' to
'ClassLibrary.ClassName' CAUSEWhen you add a Web reference to a Web Service, Microsoft
Visual Studio .NET incorrectly uses System.Data.DataSet instead of the class that implements the IXmlSerializable interface. Therefore, the Web Service method in the proxy class returns System.Data.DataSet instead of the custom class that implements the IXmlSerializable interface. Therefore, you receive the error message when you
consume the Web Service method in your Web application.RESOLUTIONTo resolve this problem, manually replace System.Data.DataSet in the proxy class with the custom class that implements the IXmlSerializable interface. To do this, follow these steps:
- In Solution Explorer, click the Web Application
project.
- On the Project menu, click Show
All Files.
- In Solution Explorer, expand Web
References, and then expand localhost.
- Expand the Reference.map node, and then
double-click the proxy file Reference.cs or
Reference.vb.
- Locate the method that incorrectly returns System.Data.DataSet. For example, locate the following code for the proxy file of the
Web Service that is used in the "More Information" section of this article:
Visual C# .NET Code [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/GetMyObject", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public System.Data.DataSet GetMyObject() {
object[] results = this.Invoke("GetMyObject", new object[0]);
return ((System.Data.DataSet)(results[0]));
} Visual Basic .NET Code <System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/GetMyObject", RequestNamespace:="http://tempuri.org/", ResponseNamespace:="http://tempuri.org/", Use:=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle:=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)> _
Public Function GetMyObject() As System.Data.DataSet
Dim results() As Object = Me.Invoke("GetMyObject", New Object(-1) {})
Return CType(results(0), System.Data.DataSet)
End Function - Manually replace System.Data.DataSet with the name of your custom class that implements the IXmlSerializable interface. For example, modify the method that you located in
step 5 as follows:
Visual C# .NET Code [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/GetMyObject", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public MyTestClass GetMyObject() {
object[] results = this.Invoke("GetMyObject", new object[0]);
return ((MyTestClass)(results[0]));
} Visual Basic .NET Code <System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/GetMyObject", RequestNamespace:="http://tempuri.org/", ResponseNamespace:="http://tempuri.org/", Use:=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle:=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)> _
Public Function GetMyObject() As MyTestClass
Dim results() As Object = Me.Invoke("GetMyObject", New Object(-1) {})
Return CType(results(0), MyTestClass)
End Function
STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are
listed at the beginning of this article.
REFERENCESFor more information, visit the following Microsoft
Developer Network (MSDN) Web sites:
Modification Type: | Minor | Last Reviewed: | 9/15/2005 |
---|
Keywords: | kbvs2002sp1sweep kbCodeGen kbWebServices kbbug KB815131 kbAudDeveloper |
---|
|