Nikki
Nikki

Reputation: 137

Console app error as follows:Index (zero based) must be greater than or equal to zero and less than the size of the argument list

string format="@\"\"\"{0}\"\" \"\"{1}\"\" \"\"{2}\"\"\",Id, ProjectId, refresh";

im storing the above as a string and passing it to processstart(appName,format). the function is as follows. im getting the mentioned error when passing the arguments

public void ProcessStart(string AppName, string format)
    {
        try
        {
            ProcessStartInfo StartInfo = new ProcessStartInfo(System.Configuration.ConfigurationManager.AppSettings[AppName].ToString());
            StartInfo.Arguments = string.Format(format);
            StartInfo.CreateNoWindow = true;
            StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            Process.Start(StartInfo);
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

Upvotes: 0

Views: 108

Answers (2)

Tim Schmelter
Tim Schmelter

Reputation: 460238

You cannot add the arguments within the format-string, this should work:

string format = "@\"\"\"{0}\"\" \"\"{1}\"\" \"\"{2}\"\"\"";
var args = string.Format(format, Id, ProjectId, refresh);
StartInfo.Arguments = args ;

Upvotes: 2

gzaxx
gzaxx

Reputation: 17600

Your format string looks like aggregated string with parameters.

Change your string format to:

string format="@\"\"\"{0}\"\" \"\"{1}\"\" \"\"{2}\"\"\";

and then

StartInfo.Arguments = string.Format(format, Id, ProjectId, refresh);

Upvotes: 1

Related Questions