Click here to Skip to main content
16,003,555 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
my .cs class file code is:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Xml;
using System.Xml.Linq;
using System.Data;
using System.Data.OleDb;
using Microsoft.VisualStudio.TestTools.WebTesting;


namespace datadrivenlib
{
    public class Class1
    {
    }
    public class AddNumbers_WTRP : WebTestRequestPlugin
    {
        public override void PreRequest(object sender, PreRequestEventArgs e)
        {

        }
        public override void PostRequest(object sender, PostRequestEventArgs e)
        {
           
        }
    }
    public class AddNumbers_WTP : WebTestPlugin
    {
        public override void PostWebTest(object sender, PostWebTestEventArgs e)
        {
            //Out_Sum

            try
            {
               
                string StrOutputFile = @"Sum_Res.csv";
                
            string a = e.WebTest.Context["DataSource_CSV.Sum_Input#csv.A"].ToString();
                string b = e.WebTest.Context["DataSource_CSV.Sum_Input#csv.B"].ToString();

                //Output Parameters
                string sum = string.Empty;

                if (e.WebTest.Outcome != Outcome.Fail)
                {
                    sum = e.WebTest.Context["Out_Sum"].ToString();
                }
                else
                {
                    e.WebTest.Outcome = Outcome.Fail;
                }
                string InsertCmd = string.Format("Insert into {0} (a,b,sum) values('" + a + "," + b + "," + sum + ")", StrOutputFile);
             


            }

            catch (System.Data.OleDb.OleDbException ex)
            {
                e.WebTest.Outcome = Outcome.Fail;
            }
        }


    }

}




Error I am Getting is:

- <soap:envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <soap:body>
- <soap:fault>
  <faultcode>soap:Client</faultcode> 
  <faultstring>System.Web.Services.Protocols.SoapException: Server was unable to read request. ---> System.InvalidOperationException: There is an error in XML document (5, 14). ---> System.FormatException: Input string was not in a correct format. at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) at System.Xml.XmlConvert.ToInt32(String s) at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read1_addition() at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer.Deserialize(XmlSerializationReader reader) at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events) --- End of inner exception stack trace --- at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events) at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle) at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters() --- End of inner exception stack trace --- at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters() at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()</faultstring> 
  <detail /> 
  </soap:fault>
  </soap:body>
  </soap:envelope>


Note: I have added a CSV file as datasource and trying to automate the webtest with the set of values provided in the CSV file.

C#
a	b
12	13
14	15
16	17
18	19
10	20
Posted
Updated 25-Oct-15 22:38pm
v4

1 solution

System.FormatException: Input string was not in a correct format. at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)

Obviously in your CSV file there is something that you try to parse to an integer, which is causing the issue because input string is not parseable to a number. Not seeing the CSV file, nor the code reading and parsing from it, prevents us to say more about that.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900