none
Process.Start (string,string) has Some Invalid Arguments RRS feed

  • Question

  • Hi everyone ..

    So I'm Trying to Start a Specific Process using some private static string ..

    I Guess it will be More Clear if i Explained it in the Code:

            private static string _filePath = System.AppDomain.CurrentDomain.BaseDirectory + "system\\";
            private static string _localeFileNames = "program.exe";
            private static string _localeCodes = "String&NumberCodeType, like K6FKY54QG9";
            private Form1.LocaleWrap _selectedLocale;
    
            private void StartNow_Click(object sender, EventArgs e)
            {
            Process.Start(Form1._filePath + Form1._localeFileNames[(int)this._selectedLocale.Locale], Form1._localeCodes[(int)this._selectedLocale.Locale]);
            }

    Hold on .. This is doesn't Explain Everything ..

    So I Added a DLL to the References Called DataTypesLib

    and i added this line in top of the Code:

    using DataTypesLib;

    When i Removed this line , the Process.Start Error was Gone !

    How is a DLL have a Effect on Windows Component ?

    Please help ..!

    Sunday, March 13, 2016 11:38 AM

Answers

  • See string (C# Reference) and the []-operator.

    Cause your using it on _localeFileNames.

    • Proposed as answer by Kristin Xie Tuesday, March 22, 2016 1:36 AM
    • Marked as answer by Kristin Xie Tuesday, March 22, 2016 6:10 AM
    Sunday, March 13, 2016 5:09 PM
  • This will compile as it will convert the single char in _localCodes at the position specified by _selectedLocale.Locale to a string:

    private void StartGameNow_Click(object sender, EventArgs e)
                {
                    Process.Start(_filePath + _localeFileNames[(int)this._selectedLocale.Locale], _localeCodes[(int)this._selectedLocale.Locale].ToString());
                }

    But the question is what arguments you want to pass to the Process.Start method? The Process.Start method accepts two strings. The first string specifies the file name and the second string specifies the command-line arguments to pass when starting the process. It is well documented on MSDN: https://msdn.microsoft.com/en-us/library/h6ak8zt5(v=vs.110).aspx

    Please refer to the following page for some examples: http://www.dotnetperls.com/process


    Hope that helps.

    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.

    • Proposed as answer by Kristin Xie Tuesday, March 22, 2016 1:36 AM
    • Marked as answer by Kristin Xie Tuesday, March 22, 2016 6:10 AM
    Sunday, March 13, 2016 5:52 PM

All replies

  • This indicates a namespace problem. For example may this DLL introduces its own Process class.

    btw, but the problem is your coding style, e.g. the inlined string building. Clean it up, then you'll see the error and you'll get a better error message.

            private static string _filePath = System.AppDomain.CurrentDomain.BaseDirectory + "system\\";
            private static string _localeFileNames = "program.exe";
            private static string _localeCodes = "String&NumberCodeType, like K6FKY54QG9";
            private LocaleWrap _selectedLocale;
    
            private void StartNow_Click(object sender, EventArgs e)
            {
                string string1 = _filePath + _localeFileNames[(int)this._selectedLocale.Locale];
                string string2 = _localeCodes[(int)this._selectedLocale.Locale];
                Process.Start(string1, string2);            
            }

    Sunday, March 13, 2016 11:59 AM
  • This indicates a namespace problem. For example may this DLL introduces its own Process class.

    btw, but the problem is your coding style, e.g. the inlined string building. Clean it up, then you'll see the error and you'll get a better error message.

            private void StartNow_Click(object sender, EventArgs e)
            {
                string string1 = _filePath + _localeFileNames[(int)this._selectedLocale.Locale];
                string string2 = _localeCodes[(int)this._selectedLocale.Locale];
                Process.Start(string1, string2);            
            }

    @Stefan

    The way for my styling code because i'm beginner in C#, i started learning one week ago.

    Well, after trying your example it gives a error: "Cannot Implicitly convert type "char" to "string""

    However, I'm not Using more than one namespace:

    Basically just this ..:

    using DataTypesLib;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
          //Classes and voids here.
        }
    }

    Also, "this._selectedLocale.Locale" might be a Integer,

    So i can't make string2 and inside of it a Integer value (int).



    Sunday, March 13, 2016 12:40 PM
  • If you have only that one using, then System.Diagnostics.Process could not be found.

    All classes are unambigiously identified by thier fully qualified name (System.Diagnostics.Process is the full name of that class). Even if you do not write it, that is what is actually compiled.
    Using directives allow you to skip writing the fully qualified name everytime, as long as there is only one class of that (short) name in all the used namespaces combined.

    For example there are at least 3 totally distinct classes called "Timer" in the entire .NET Framework:

    System.Timers.Timer

    System.Windows.Forms.Timer

    System.Web.UI.Timer

    As long as you have one and only one of the namespaces containing a "Timer" class, just "Timer" is enough for the Compiler to imply wich one you mean.
    But the moment you use more then 1 of these namespaces, the compiler needs more data to identify them unambigiously. Indeed the best way is to remove all but one of the usings entirely and use the fully qualified name for the timer classes. Type Aliases can help to make that write work shorter.

    Sunday, March 13, 2016 2:22 PM
  • Thank you for Explaining but still didn't get the idea ..

    How do you Suggest Doing this ?

    My Full Code :

    using DataTypesLib;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.Diagnostics;
    using System.Runtime.Serialization.Formatters.Binary;
    using System.Threading;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private static string _filePath = System.AppDomain.CurrentDomain.BaseDirectory + "system\\";
            private static string _localeFileNames = "program.exe";
            private static string _localeCodes = "String&NumberCodeType, like K6FKY54QG9";
            private LocaleWrap _selectedLocale;
    
            public class Server
            {
                public string Name
                {
                    get;
                    set;
                }
    
                public string Ip
                {
                    get;
                    set;
                }
    
                public string Port
                {
                    get;
                    set;
                }
    
                public bool IsOfficialSrv
                {
                    get;
                    set;
                }
    
                public string FileName
                {
                    get;
                    set;
                }
    
                public override string ToString()
                {
                    return this.Name;
                }
            }
    
           
            private void StartGameNow_Click(object sender, EventArgs e)
            {
                Process.Start(_filePath + _localeFileNames[(int)this._selectedLocale.Locale], _localeCodes[(int)this._selectedLocale.Locale]);
            }
    
            public class LocaleWrap
            {
                public string Name
                {
                    get;
                    set;
                }
                
                public Locale Locale
                {
                    get;
                    set;
                }
    
                public override string ToString()
                {
                    return this.Name;
                }
            }
    
        }
    }
    

    :\ ..

    Sunday, March 13, 2016 5:07 PM
  • See string (C# Reference) and the []-operator.

    Cause your using it on _localeFileNames.

    • Proposed as answer by Kristin Xie Tuesday, March 22, 2016 1:36 AM
    • Marked as answer by Kristin Xie Tuesday, March 22, 2016 6:10 AM
    Sunday, March 13, 2016 5:09 PM
  • This will compile as it will convert the single char in _localCodes at the position specified by _selectedLocale.Locale to a string:

    private void StartGameNow_Click(object sender, EventArgs e)
                {
                    Process.Start(_filePath + _localeFileNames[(int)this._selectedLocale.Locale], _localeCodes[(int)this._selectedLocale.Locale].ToString());
                }

    But the question is what arguments you want to pass to the Process.Start method? The Process.Start method accepts two strings. The first string specifies the file name and the second string specifies the command-line arguments to pass when starting the process. It is well documented on MSDN: https://msdn.microsoft.com/en-us/library/h6ak8zt5(v=vs.110).aspx

    Please refer to the following page for some examples: http://www.dotnetperls.com/process


    Hope that helps.

    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.

    • Proposed as answer by Kristin Xie Tuesday, March 22, 2016 1:36 AM
    • Marked as answer by Kristin Xie Tuesday, March 22, 2016 6:10 AM
    Sunday, March 13, 2016 5:52 PM
  • Well , it is still Confusing me because it gives a error on starting the Exe :

    "file not found" ..

     private static string _filePath = System.AppDomain.CurrentDomain.BaseDirectory + "system\\";
     private static string _localeFileNames = "program.exe";

    I'm passing a GameEngine Running ..

    Using a Specific Code & Locale , Which is might be "0" because it's a Int.

    Sunday, March 13, 2016 7:30 PM
  • Still Unsolved ..
    Tuesday, March 15, 2016 1:34 PM
  • Have you read the links I've provided?

    Tuesday, March 15, 2016 1:44 PM