Re: No accessible overloaded

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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("type = User - " & Session("User").UserID.GetType.ToString())
trace.warn("type = ApplicantID - " &
Session("ApplicantID").GetType.ToString())
HistoryLog.WriteHistoryLog(13,"Application Filed for: " &
HeaderJobTitle.Text,Session("User").UserID,session("ApplicantID"))
************************************************************

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

It turns out if I change the above code to:

HistoryLog.WriteHistoryLog(13,"Application Filed for: " &
HeaderJobTitle.Text,Session("User").UserID,Convert.ToInt32(session("ApplicantID")))

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("ApplicantID") happened to be ten billion (which doesn't fit in an Integer) ?


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

No accessible overloaded 'HistoryLog.WriteHistoryLog' 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 (historyActionID as Integer,detail as
String,userID as Integer,applicantID 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("ApplicantID") 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@xxxxxxxxxxxxxx
The address is real, but unread - please reply to the group
For VB and C# questions - tell us which version
.



Relevant Pages

  • Re: Is it compiler strangeness ?
    ... can fit in an unsigned int, so it has the type unsigned int. ... conversion from unsigned to signed. ... unsigned type, so with j equal to -1, j equals the largest value ...
    (microsoft.public.vc.language)
  • Re: [9fans] 8c puzzling behavior
    ... fit in an int so it is an unsigned int. ... *same* type before any signedness conversion but can't find ... typedef unsigned long long uvlong; ...
    (comp.os.plan9)
  • Re: FTP
    ... Dim dwFileAttributes As Integer ... Public cAlternate As String ... > public int dwHighDateTime; ... > public static extern IntPtr InternetConnect( ...
    (microsoft.public.dotnet.languages.vb)
  • [PATCH] I2C: Coding style cleanups to via686a
    ... (These conversions were contributed by Jonathan Teh Soon Yew ... int inNum) ... smooth function fit to the data will allow us to get better precision. ... - VIA register values 0-255. ...
    (Linux-Kernel)
  • Re: Problem with linker
    ... but to have actually written a default constructor. ... such as overloading on int and pointer types. ... conversion of 0 to CString requires a user-defined conversion, ... acceleration operator *(distance d, time_squared t2); ...
    (microsoft.public.vc.mfc)