Error: System.ArgumentException: Cannot convert to System.Int32.

Discussion in 'ASP .Net' started by Simon Harris, Apr 27, 2005.

  1. Simon Harris

    Simon Harris Guest

    I have created a web service, which when I call in my browser presents the
    text form etc. When I click the button, I get this error:

    System.ArgumentException: Cannot convert to System.Int32.
    Parameter name: type ---> System.FormatException: Input string was not in
    a
    correct format.
    at System.Number.ParseInt32(String s, NumberStyles style,
    NumberFormatInfo info)
    at System.String.System.IConvertible.ToInt32(IFormatProvider provider)
    at System.Convert.ChangeType(Object value, Type conversionType,
    IFormatProvider provider)
    at System.Web.Services.Protocols.ScalarFormatter.FromString(String
    value,
    Type type)
    --- End of inner exception stack trace ---
    at System.Web.Services.Protocols.ScalarFormatter.FromString(String
    value,
    Type type)
    at
    System.Web.Services.Protocols.ValueCollectionParameterReader.Read(NameValu
    eCollection
    collection)
    at
    System.Web.Services.Protocols.HtmlFormParameterReader.Read(HttpRequest
    request)
    at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()
    at System.Web.Services.Protocols.WebServiceHandler.Invoke()
    at
    System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()This
    seems to happen only when I have parameters of different data types, e.g.:

    Works:
    ======
    <WebMethod()> _
    Public Function GetAddresses(ByVal a As String, ByVal b As String) As
    DataSet

    Causes Error:
    ===========
    <WebMethod()> _
    Public Function GetAddresses(ByVal a As String, ByVal b As Integer) As
    DataSet

    Any ideas/suggestions will be much appreciated.



    Regards,

    Simon.



    --
    I am using the free version of SPAMfighter for private users.
    It has removed 2053 spam emails to date.
    Paying users do not have this message in their emails.
    Try www.SPAMfighter.com for free now!
     
    Simon Harris, Apr 27, 2005
    #1
    1. Advertising

  2. Hi Simon,

    Are you able to show some of the code that is calling this Web service?

    If the SOAP defaults the type to a string, your Web service is going to have
    the problem you're seeing if it expects an integer.

    Ken
    MVP [ASP.NET]

    "Simon Harris" <> wrote in message
    news:...
    >I have created a web service, which when I call in my browser presents the
    > text form etc. When I click the button, I get this error:
    >
    > System.ArgumentException: Cannot convert to System.Int32.
    > Parameter name: type ---> System.FormatException: Input string was not in
    > a
    > correct format.
    > at System.Number.ParseInt32(String s, NumberStyles style,
    > NumberFormatInfo info)
    > at System.String.System.IConvertible.ToInt32(IFormatProvider provider)
    > at System.Convert.ChangeType(Object value, Type conversionType,
    > IFormatProvider provider)
    > at System.Web.Services.Protocols.ScalarFormatter.FromString(String
    > value,
    > Type type)
    > --- End of inner exception stack trace ---
    > at System.Web.Services.Protocols.ScalarFormatter.FromString(String
    > value,
    > Type type)
    > at
    > System.Web.Services.Protocols.ValueCollectionParameterReader.Read(NameValu
    > eCollection
    > collection)
    > at
    > System.Web.Services.Protocols.HtmlFormParameterReader.Read(HttpRequest
    > request)
    > at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()
    > at System.Web.Services.Protocols.WebServiceHandler.Invoke()
    > at
    > System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()This
    > seems to happen only when I have parameters of different data types, e.g.:
    >
    > Works:
    > ======
    > <WebMethod()> _
    > Public Function GetAddresses(ByVal a As String, ByVal b As String) As
    > DataSet
    >
    > Causes Error:
    > ===========
    > <WebMethod()> _
    > Public Function GetAddresses(ByVal a As String, ByVal b As Integer) As
    > DataSet
    >
    > Any ideas/suggestions will be much appreciated.
    >
    >
    >
    > Regards,
    >
    > Simon.
    >
    >
    >
    > --
    > I am using the free version of SPAMfighter for private users.
    > It has removed 2053 spam emails to date.
    > Paying users do not have this message in their emails.
    > Try www.SPAMfighter.com for free now!
    >
    >
     
    Ken Cox [Microsoft MVP], Apr 27, 2005
    #2
    1. Advertising

  3. Simon Harris

    Simon Harris Guest

    "Ken Cox [Microsoft MVP]" <> wrote in message
    news:%...
    > Hi Simon,
    >
    > Are you able to show some of the code that is calling this Web service?
    >
    > If the SOAP defaults the type to a string, your Web service is going to
    > have the problem you're seeing if it expects an integer.
    >
    > Ken
    > MVP [ASP.NET]


    Hi Ken,

    I solved it earlier - You were correct, it was expecting an Int, I was
    passing it null.

    Many Thanks for your reply.

    Simon.
     
    Simon Harris, Apr 27, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Craig Deelsnyder
    Replies:
    1
    Views:
    4,653
    =?Utf-8?B?U2hhd24gS2VubmV5?=
    Jul 19, 2004
  2. =?Utf-8?B?SGlmbmkgU2hhaHphcmQ=?=

    Invalid cast from System.Int32 to System.Byte[].

    =?Utf-8?B?SGlmbmkgU2hhaHphcmQ=?=, Feb 15, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    3,805
    William F. Robertson, Jr.
    Feb 15, 2005
  3. Simon Harris
    Replies:
    0
    Views:
    758
    Simon Harris
    Apr 27, 2005
  4. keithb
    Replies:
    3
    Views:
    18,675
    =?ISO-8859-1?Q?G=F6ran_Andersson?=
    May 7, 2006
  5. Replies:
    20
    Views:
    9,813
    licebmi
    Sep 7, 2009
Loading...

Share This Page