No accessible overloaded

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tshad

    #1

    No accessible overloaded

    I am getting the following error which makes no sense. I am doing this in
    asp.net. I get the following error:

    No accessible overloaded

    If you look at the error, there is one overloaded function that can be
    called (int, string, int, int).

    The first variable is constant that should work fine as an int and works
    everywhere else.
    The second variable is a string.
    The third variable is a System.Int32. (from trace)
    The fourth variable is a System.Int64. (from trace)

    The code:
    *************** *************** *************** *********
    trace.warn("typ e = User - " & Session("User") .UserID.GetType .ToString())
    trace.warn("typ e = ApplicantID - " &
    Session("Applic antID").GetType .ToString())
    HistoryLog.Writ eHistoryLog(13, "Applicatio n Filed for: " &
    HeaderJobTitle. Text,Session("U ser").UserID,se ssion("Applican tID"))
    *************** *************** *************** ***************

    Trace results:
    *************** ***********
    type = User - System.Int32
    type = ApplicantID - System.Int64
    *************** *************

    It turns out if I change the above code to:

    HistoryLog.Writ eHistoryLog(13, "Applicatio n Filed for: " &
    HeaderJobTitle. Text,Session("U ser").UserID,Co nvert.ToInt32(s ession("Applica ntID")))

    I thought that the different sizes of integers were interchangeable
    (obviously the conversion works OK). I would have thought that an Int64
    would work fine for an Integer field.

    The error messages:
    *************** *************** *************** ***********
    Unhandled Execution Error

    No accessible overloaded 'HistoryLog.Wri teHistoryLog' can be called with
    these arguments without a narrowing conversion:
    Public Sub WriteHistoryLog ( ByVal historyActionID As Integer, ByVal detail
    As String, ByVal userID As Integer, ByVal applicantID As Integer )
    Public Sub WriteHistoryLog ( ByVal historyActionID As Integer, ByVal detail
    As String, ByVal firstName As String, ByVal lastName As String )
    at
    Microsoft.Visua lBasic.Compiler Services.VBBind er.set_Internal Throw(Exception
    Value)
    at Microsoft.Visua lBasic.Compiler Services.VBBind er.BindToMethod (BindingFlags
    bindingAttr, MethodBase[] match, Object[]& args, ParameterModifi er[]
    modifiers, CultureInfo culture, String[] names, Object& ObjState)
    at Microsoft.Visua lBasic.Compiler Services.VBBind er.InvokeMember (String name,
    BindingFlags invokeAttr, Type objType, IReflect objIReflect, Object target,
    Object[] args, ParameterModifi er[] modifiers, CultureInfo culture, String[]
    namedParameters )
    at
    Microsoft.Visua lBasic.Compiler Services.LateBi nding.InternalL ateCall(Object
    o, Type objType, String name, Object[] args, String[] paramnames, Boolean[]
    CopyBack, Boolean IgnoreReturn)
    at Microsoft.Visua lBasic.Compiler Services.LateBi nding.LateCall( Object o,
    Type objType, String name, Object[] args, String[] paramnames, Boolean[]
    CopyBack)
    at ASP.application CompletedView_a spx.SubmitIt_Cl ick(Object s,
    ImageClickEvent Args e) in
    C:\Inetpub\wwwr oot\staffingwor kshop\applicant \secure\applica tionCompletedVi ew.aspx:line
    666
    at System.Web.UI.W ebControls.Imag eButton.OnClick (ImageClickEven tArgs e)
    at
    System.Web.UI.W ebControls.Imag eButton.System. Web.UI.IPostBac kEventHandler.R aisePostBackEve nt(String
    eventArgument)
    at System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler
    sourceControl, String eventArgument)
    at System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData)
    at System.Web.UI.P age.ProcessRequ estMain()
    *************** *************** *************** *************** *******

    Here is the Function Call that is being called

    Public Shared sub WriteHistoryLog (historyActionI D as Integer,detail as
    String,userID as Integer,applica ntID as Integer)

    Why doesn't this work with the convert function?

    Thanks,

    Tom



  • Larry Lard

    #2
    Re: No accessible overloaded

    tshad wrote:
    I am getting the following error which makes no sense. I am doing this in
    asp.net. I get the following error:
    >
    No accessible overloaded
    >
    If you look at the error, there is one overloaded function that can be
    called (int, string, int, int).
    In this group we would prefer to say (Integer, String, Integer,
    Integer), but we know what you mean.
    >
    The first variable is constant that should work fine as an int and works
    everywhere else.
    Well, if it's a constant that the compiler thinks looks like an Integer,
    yes.
    The second variable is a string.
    The third variable is a System.Int32. (from trace)
    The fourth variable is a System.Int64. (from trace)
    Aha.
    >
    The code:
    *************** *************** *************** *********
    trace.warn("typ e = User - " & Session("User") .UserID.GetType .ToString())
    trace.warn("typ e = ApplicantID - " &
    Session("Applic antID").GetType .ToString())
    HistoryLog.Writ eHistoryLog(13, "Applicatio n Filed for: " &
    HeaderJobTitle. Text,Session("U ser").UserID,se ssion("Applican tID"))
    *************** *************** *************** ***************
    >
    Trace results:
    *************** ***********
    type = User - System.Int32
    type = ApplicantID - System.Int64
    *************** *************
    >
    It turns out if I change the above code to:
    >
    HistoryLog.Writ eHistoryLog(13, "Applicatio n Filed for: " &
    HeaderJobTitle. Text,Session("U ser").UserID,Co nvert.ToInt32(s ession("Applica ntID")))
    It works, I presume.
    >
    I thought that the different sizes of integers were interchangeable
    (obviously the conversion works OK). I would have thought that an Int64
    would work fine for an Integer field.
    What would you like to happen if session("Applic antID") happened to be
    ten billion (which doesn't fit in an Integer) ?
    >
    The error messages:
    *************** *************** *************** ***********
    Unhandled Execution Error
    >
    No accessible overloaded 'HistoryLog.Wri teHistoryLog' can be called with
    these arguments without a narrowing conversion:
    As it turns out, the full error message does tell you exactly what the
    problem is...
    *************** *************** *************** *************** *******
    >
    Here is the Function Call that is being called
    >
    Public Shared sub WriteHistoryLog (historyActionI D as Integer,detail as
    String,userID as Integer,applica ntID as Integer)
    >
    Why doesn't this work with the convert function?
    I though it *does* work when you use Convert.ToInt32 (or CInt) ?

    One the the things about VB.NET is that it likes to be type-safe,
    especially if you (as you always should) have Option Strict On. One of
    the type safety features is that when you are doing something which
    could result in the loss of information, you must be explicit about it.

    So you can say

    Dim ss As Short = 32
    Dim ii As Integer = ss


    with no problem, because all Short values can be held in an Integer. But
    were you to try

    Dim ii As Integer = 32
    Dim ss As Short = ii

    you would get a warning, because Integer to Short is a *narrowing*
    conversion - there are some Integer values which can't be held in a
    Short, so such an assignment is *unsafe*. Even though it is obvious to
    us that 32 will fit in a Short, the compiler pretty much only works one
    line at a time, and all it sees is that you are trying to fit a
    (potential) quart in a pint pot.

    It's exactly the same in your problem. Sure, session("Applic antID")
    might only ever *be* a small number, but the *variable* is an Int64, so
    the compiler will not *automatically* convert it to an Int32, which is
    what would have to happen for the calling signature to match the
    definition signature. Thus the error message.

    --
    Larry Lard
    larrylard@googl email.com
    The address is real, but unread - please reply to the group
    For VB and C# questions - tell us which version

    Comment

    • tshad

      #3
      Re: No accessible overloaded

      "Larry Lard" <larrylard@goog lemail.comwrote in message
      news:4is3itF57d 5dU1@individual .net...
      tshad wrote:
      >I am getting the following error which makes no sense. I am doing this
      >in asp.net. I get the following error:
      >>
      >No accessible overloaded
      >>
      >If you look at the error, there is one overloaded function that can be
      >called (int, string, int, int).
      >
      In this group we would prefer to say (Integer, String, Integer, Integer),
      but we know what you mean.
      Sorry, my C is showing through.
      >
      >>
      >The first variable is constant that should work fine as an int and works
      >everywhere else.
      >
      Well, if it's a constant that the compiler thinks looks like an Integer,
      yes.
      >
      >The second variable is a string.
      >The third variable is a System.Int32. (from trace)
      >The fourth variable is a System.Int64. (from trace)
      >
      Aha.
      >
      >>
      >The code:
      >************** *************** *************** **********
      >trace.warn("ty pe = User - " & Session("User") .UserID.GetType .ToString())
      >trace.warn("ty pe = ApplicantID - " &
      >Session("Appli cantID").GetTyp e.ToString())
      > HistoryLog.Writ eHistoryLog(13, "Applicatio n Filed for: " &
      >HeaderJobTitle .Text,Session(" User").UserID,s ession("Applica ntID"))
      >************** *************** *************** *************** *
      >>
      >Trace results:
      >************** ************
      >type = User - System.Int32
      >type = ApplicantID - System.Int64
      >************** **************
      >>
      >It turns out if I change the above code to:
      >>
      > HistoryLog.Writ eHistoryLog(13, "Applicatio n Filed for: " &
      >HeaderJobTitle .Text,Session(" User").UserID,C onvert.ToInt32( session("Applic antID")))
      >
      It works, I presume.
      Yes it does.
      >
      >>
      >I thought that the different sizes of integers were interchangeable
      >(obviously the conversion works OK). I would have thought that an Int64
      >would work fine for an Integer field.
      >
      What would you like to happen if session("Applic antID") happened to be ten
      billion (which doesn't fit in an Integer) ?
      >
      But that would never happen.

      I'm not really sure why it is showing as Int64, but I would have thought
      that it would convert the type unless, as you say, the value is out of
      bounds. Obviously that is not the case, as you explain below.

      Thanks,

      Tom
      >>
      >The error messages:
      >************** *************** *************** ************
      >Unhandled Execution Error
      >>
      >No accessible overloaded 'HistoryLog.Wri teHistoryLog' can be called with
      >these arguments without a narrowing conversion:
      >
      As it turns out, the full error message does tell you exactly what the
      problem is...
      >************** *************** *************** *************** ********
      >>
      >Here is the Function Call that is being called
      >>
      > Public Shared sub WriteHistoryLog (historyActionI D as Integer,detail as
      >String,userI D as Integer,applica ntID as Integer)
      >>
      >Why doesn't this work with the convert function?
      >
      I though it *does* work when you use Convert.ToInt32 (or CInt) ?
      Sorry, I meant "does".
      >
      One the the things about VB.NET is that it likes to be type-safe,
      especially if you (as you always should) have Option Strict On. One of the
      type safety features is that when you are doing something which could
      result in the loss of information, you must be explicit about it.
      >
      So you can say
      >
      Dim ss As Short = 32
      Dim ii As Integer = ss
      >
      >
      with no problem, because all Short values can be held in an Integer. But
      were you to try
      >
      Dim ii As Integer = 32
      Dim ss As Short = ii
      >
      you would get a warning, because Integer to Short is a *narrowing*
      conversion - there are some Integer values which can't be held in a Short,
      so such an assignment is *unsafe*. Even though it is obvious to us that 32
      will fit in a Short, the compiler pretty much only works one line at a
      time, and all it sees is that you are trying to fit a (potential) quart in
      a pint pot.
      >
      It's exactly the same in your problem. Sure, session("Applic antID") might
      only ever *be* a small number, but the *variable* is an Int64, so the
      compiler will not *automatically* convert it to an Int32, which is what
      would have to happen for the calling signature to match the definition
      signature. Thus the error message.
      >
      --
      Larry Lard
      larrylard@googl email.com
      The address is real, but unread - please reply to the group
      For VB and C# questions - tell us which version

      Comment

      • Larry Lard

        #4
        Re: No accessible overloaded

        tshad wrote:
        "Larry Lard" <larrylard@goog lemail.comwrote in message
        news:4is3itF57d 5dU1@individual .net...
        >tshad wrote:
        >>I thought that the different sizes of integers were interchangeable
        >>(obviously the conversion works OK). I would have thought that an Int64
        >>would work fine for an Integer field.
        >What would you like to happen if session("Applic antID") happened to be ten
        >billion (which doesn't fit in an Integer) ?
        >>
        >
        But that would never happen.
        >
        I'm not really sure why it is showing as Int64, but I would have thought
        that it would convert the type unless, as you say, the value is out of
        bounds. Obviously that is not the case, as you explain below.
        The compiler has to be strict; it can't know that the applicant ID
        values 'will always' be convertible, unless we help it by providing the
        explicit conversion - by doing so we are saying "Don't worry dear
        compiler, I take full responsibility for the runtime problems that might
        occur by trying to convert a too-large Int64 into an Int32. Please carry
        on compiling."

        As to why it's an Int64 to start with - I don't actually know enough
        ASP.NET to be able to suggest an explanation.


        --
        Larry Lard
        larrylard@googl email.com
        The address is real, but unread - please reply to the group
        For VB and C# questions - tell us which version

        Comment

        Working...