none
Exception has been thrown by the target of an invocation while using process.start

    Question

  • hi MVP'S i am designing a voice reconigation software and i am having problem when try to start the process please help me out Thanx in Advance

    here is the code:

        void
     engine_SpeechRecognized(object
     sender, SpeechRecognizedEventArgs e)
    {

    int index = 0;
    //commandform is an object of form
    //commandArray is an arraylist which include all the commands as string
    foreach (string s in commandform.commandArray)
    {
    //commands are matched with spoken command
    if (s.Contains(e.Result.Text))
    {

    if (s.Contains("shell" ))
    {
    //here that process should be but getting exception ;x
    Process.Start(strCommands[index].ToString());
    //if try process.start("c:\\") i wont get error but i dont want constant string in it
    break ;
    }
    index++;
    Console.WriteLine(e.Result.Text);
    }
    }

    }

    <input id="insert" name="insert" type="button" value="Insert" />  
    Tuesday, February 22, 2011 4:10 PM

Answers

  • Hey guys i finally did it myself thanx to those who helped me here is the code

     

     

    string[] str = s.Split('|');
                processinfo=new ProcessStartInfo(@"c:\windows\system32\cmd.exe ","/c start "+str[1]);
                processinfo.CreateNoWindow = false;
                processinfo.WindowStyle = ProcessWindowStyle.Hidden;
                Process.Start(processinfo);
    
    i hope it will help some one else

     

    • Marked as answer by SAQYG Thursday, February 24, 2011 2:29 PM
    Thursday, February 24, 2011 2:29 PM

All replies

  • Hi,

    Can you please describe what is the runtime value of strCommands[index].ToString()

    Also,it would be helpful if you can mention the complete error message.

    A tip would be try pasting the value of strCommands[index].ToString() in command prompt and see if the process launches or not. If it doesnt, then the reason is that the system couldnt find the file and you will need to set some environment variables, etc for the system to recognise it.

    Thanks,

    Anuj

    Tuesday, February 22, 2011 6:30 PM
  • Hi brother Anuj thanx for reply

    value of strcommands[index]="c:\\windows\\system32\\taskmgr.exe"

    i checked it command prompt and run it works perfect

    if i made this string constant and pass it to the process.start it works but i dont want it in that way i dont have clue why its happening anyways

    for your quick reply

    System.Reflection.TargetInvocationException was unhandled
     Message="Exception has been thrown by the target of an invocation."
     Source="mscorlib"
     StackTrace:
        at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
        at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
        at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
        at System.Delegate.DynamicInvokeImpl(Object[] args)
        at System.Speech.Internal.AsyncSerializedWorker.WorkerProc(Object ignored)
        at System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(Object state)
        at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
        at System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack)
        at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state)
     InnerException: System.ComponentModel.Win32Exception
        Message="No application is associated with the specified file for this operation"
        Source="System"
        ErrorCode=-2147467259
        NativeErrorCode=1155
        StackTrace:
          at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
          at System.Diagnostics.Process.Start()
          at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
          at System.Diagnostics.Process.Start(String fileName)
          at voicesreconigationusingclasses.voiceReconigatioon.engine_SpeechRecognized(Object sender, SpeechRecognizedEventArgs e) in C:\Documents and Settings\Raja Amir\My Documents\Visual Studio 2008\Projects\voicesreconigationusingclasses\voicesreconigationusingclasses\voiceReconigatioon.cs:line 55
          at System.Speech.Recognition.SpeechRecognitionEngine.SpeechRecognizedProxy(Object sender, SpeechRecognizedEventArgs e)
        InnerException: 
    
    
    

    Wednesday, February 23, 2011 6:30 AM
  • right now i have tried many things but does't work here are those things

    1-calling process.start from another form

    2-try to call from direct API method shellexecuteEx it gives the same error

    3-making custom event and than fire on command match still the same error

    do u have any suggestions this thing is getting the hell out of me

     

    Wednesday, February 23, 2011 1:28 PM
  • Hi Saqyg,

    Welcome to this fourm and all the participate.

    This thread is off-topic in the fourm. I will move it to the c# generic fourm. Thanks to understand.

    Process.Start Method  http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start.aspx

    Have a good day.


    If it's helpful for you, Please vote or mark. Thank you!

    David Peng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, February 24, 2011 6:42 AM
    Moderator
  • no problem at all i am just new and understanding this forum...
    Thursday, February 24, 2011 11:45 AM
  • Hey guys i finally did it myself thanx to those who helped me here is the code

     

     

    string[] str = s.Split('|');
                processinfo=new ProcessStartInfo(@"c:\windows\system32\cmd.exe ","/c start "+str[1]);
                processinfo.CreateNoWindow = false;
                processinfo.WindowStyle = ProcessWindowStyle.Hidden;
                Process.Start(processinfo);
    
    i hope it will help some one else

     

    • Marked as answer by SAQYG Thursday, February 24, 2011 2:29 PM
    Thursday, February 24, 2011 2:29 PM