Saturday 24 August 2013

Cannot Serialize The Data Table - Web Service

Leave a Comment
System.InvalidOperationException: There was an error generating the XML document. ---> 
System.InvalidOperationException: Cannot serialize the DataTable. DataTable name is not set.

This is the error occur when you create method in webservice with data type "DataTable". For Example like this :


    [WebMethod]
    public DataTable test1()
    {
        DataTable testTable = new DataTable();
        return testTable;
    }


The Example above will lead to the Error "Cannot Serialize The Data Table"

This error because of method in WebService try to return result of DataTable to whoever request  it, but unfortunately the DataTable do not have their own name. So the quick solution for this error is put the name for DataTable like this :

The Solutions

     [WebMethod]
     public DataTable test1()
     {
          DataTable testTable = new DataTable("Table1");
          return testTable;
     }



By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)

0 comments:

Post a Comment

Subscribe to our newsletter to get the latest updates to your inbox.

Your email address is safe with us!




Founder of developersnote.com, love programming and help others people. Work as Software Developer. Graduated from UiTM and continue study in Software Engineering at UTMSpace. Follow him on Twitter , or Facebook or .



Powered by Blogger.