Link to home
Start Free TrialLog in
Avatar of Wayne Barron
Wayne BarronFlag for United States of America

asked on

ASP.NET (VB) Specified argument was out of the range of valid values.

Hello all;

OK, It seems there was an update that messed this up, however. I am unsure of when this happened.
I just recently was made aware of it.

Works fine in Windows 10, but not in Win16 Server
This is from an upload script using Uploadify.

Running the site through Visual Studio for testing, and the below is the error code.

Error Code

System.ArgumentOutOfRangeException: 'Specified argument was out of the range of valid values.
Parameter name: startIndex'

Errors on this line (Line 120)
ImageToSave.Save(context.Server.MapPath(Path.Combine(thPath, getFile.Insert(getFile.LastIndexOf("."c), ""))), ImageFormat.Jpeg)

Open in new window


When running the site through Google Chrome, and it errors out (IO Error)
I check the Event Viewer on the Server, it gives


Exception information:
    Exception type: ArgumentOutOfRangeException
    Exception message: Specified argument was out of the range of valid values.
Parameter name: startIndex
   at System.String.Insert(Int32 startIndex, String value)
   at UploadVB.ProcessRequest(HttpContext context) in G:\Inetpub\wwwroot\sitename.com\images\UploadVB.ashx:line 120
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Any assistance on this would be great.
Wayne
Avatar of Nikoloz Khelashvili
Nikoloz Khelashvili
Flag of Georgia image

what means   "."c  here?

ImageToSave.Save(context.Server.MapPath(Path.Combine(thPath, getFile.Insert(getFile.LastIndexOf("."c), ""))), ImageFormat.Jpeg)

Open in new window

Avatar of Bill Prew
Bill Prew

I expect this is happening because when you look for the last period character it does not exist and so this function is returning -1.

getFile.LastIndexOf("."c)

That is then passed as the index to:

getFile.Insert(getFile.LastIndexOf("."c), "")

Check what the value is of getFile when the error is thrown?


»bp
*NO POINTS*

@Nikoloz,

"."c identifies what would normally be defined as a string as a literal CHAR value.

https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/constants-enums/constant-and-literal-data-types

-saige-
Avatar of Wayne Barron

ASKER

Hello all.
From my post.
>>> Works fine in Windows 10, but not in Win16 Server

OK, with that stated.
I can run the same script within Visual Studio and it uploads the file and inserts into the database.
when I run it on Windows 10, it uploads the file and inserts into the database.
On Windows 2016 Server, I get this error.

Any idea's on what to look for?

@bp
>>> Check what the value is of getFile when the error is thrown?
How would I check this??
Can you check saving path full length? Maybe because of path maxlength limitation? 247 symbols, as I remember
How would I check this??

You mentioned that you had run it through Visual Studio, so just do that and set a breakpoint on that line and when you get to it examine the variable value.


»bp
bp
It works through VS.
I'm confused, in your original post you mentioned the following, is that no longer the case?

Running the site through Visual Studio for testing, and the below is the error code.

Error Code
System.ArgumentOutOfRangeException: 'Specified argument was out of the range of valid values.
Parameter name: startIndex'


»bp
Your absolutely correct BP.
Scratch my last comment.
The issue is this.
The script is running a Flash upload (Uploadify)
So, I cannot see anything passed through it.
The only thing I get from it is an IO Error
Sorry if I keep asking the same stuff over again, just want to understand the best I can.

So this is not a line of code that you have in VS and can see and set a breakpoint on?

ImageToSave.Save(context.Server.MapPath(Path.Combine(thPath, getFile.Insert(getFile.LastIndexOf("."c), ""))), ImageFormat.Jpeg)

If it is, then when you debug and get to that break you can't display the value of getfile?


»bp
This is what I get in Google Chrome.

Failed to load resource: the server responded with a status of 500 (Internal Server Error)
Google Chrome Console (Developer Tools)
Is where I get that message I posted above.

I set a breakpoint on that line, but I am not seeing anything on the page except IO error in the Flash.
And then in CONSOLE, I see.
Failed to load resource: the server responded with a status of 500 (Internal Server Error)

But there is nothing showing in VS.

I know my way around VS, but there is still a LOT I don't know how to do.
Debugging, I have not had a lot of experience with, as most of the codes I have written have pretty much worked.
So, any hints or advice on the debugging to get the value to show would be great.
Do you know what this is trying to accomplish?  Without knowing the application I'd interpret it as "take the string getFile, locate the rightmost period in it, and insert nothing there".  That doesn't make a lot of sense to me unless it's some sort of a trick I am not aware of, which is certainly possible.

getFile.Insert(getFile.LastIndexOf("."c), ""))


»bp
Here is the script for this part.
What it does is creates the image for the specified file SIZE.

                Dim pos As Integer = clear.LastIndexOf(".")
                Dim ImageToSave As System.Drawing.Image = resizeImage(System.Drawing.Image.FromStream(postedFile.InputStream), New Size(130,110))
                ImageToSave.Save(context.Server.MapPath(Path.Combine(thPath, getFile.Insert(getFile.LastIndexOf("."c), ""))), ImageFormat.Jpeg)

Open in new window


Also would like to mention, this script is over 4 years old.
I have been using it on different sites for this time.
It has worked in all systems it has been on.
Win2k3, WinXP, Win10, Win2016
I am really not sure WHEN it stopped working, as I had not used my sites since I started hosting in-house about 6-months ago, and everything worked then.
Now, I was made aware that it is not working on a customers site the other day.
I tested it in the 2016 server and got the errors.
Tested it on Win10, and it worked like expected.

So, I am at a crossfire on this one.
In order to make it work, I would do something like this:
Dim pos As Integer = clear.LastIndexOf(".")
Dim periodPosition As Integer = getFile.LastIndexOf("."c)
Dim ImageToSave As System.Drawing.Image = resizeImage(System.Drawing.Image.FromStream(postedFile.InputStream), New Size(130,110))
ImageToSave.Save(context.Server.MapPath(Path.Combine(thPath, If(periodPosition <> -1, getFile.Insert(periodPosition, ""), ""))), ImageFormat.Jpeg)

Open in new window

-saige-
Given that I see no purpose for:

getFile.Insert(getFile.LastIndexOf("."c), "")

then perhaps you just remove it, as in:

ImageToSave.Save(context.Server.MapPath(Path.Combine(thPath, getFile)), ImageFormat.Jpeg)


»bp
@Bill, and @-saige-
I did as you both suggested, and this is the error I received.


System.ArgumentNullException: 'Value cannot be null.
Parameter name: path1'

It has to have everything in order for it to work.

I am really unsure what happened, I am at a complete loss.
It might be helpful if we could see all the code, not just these few lines.


»bp
Hey, bp.
I have a demo of it, let me make sure I can make it reproduce this error and I will send you both over a link to download.
Okay.
OK. Here is a link to the demo project.
This is what I use for people to download the source from.

This works in Visual Studio & Windows 10 but NOT in Windows 2016 Server

https://www.cffcs.com/Tutorials/carrzkiss/22/upload/scripts.zip
FIXED!!!!!!!!!!

Have to give permission to the folder
AUTHENTICATED USERS

Once this is set, the script works.
Wonder what changed, but that fixes it.
Excellent, glad you were able to track that down!


»bp
ASKER CERTIFIED SOLUTION
Avatar of Wayne Barron
Wayne Barron
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I created an Article on our Knowledge Base for this as well.
Giving Instructions on how to properly add in the permissions for those that may now know the proper procedure.
https://www.cffkb.com/Main.asp?irid=218&Type=Article

Wayne