TargetInvocationException



  • Hi
    Ich bins mal wieder 😉
    brauch nochmal bitte Hilfe von euch bin am verzweifeln 😞 .

    Also wollte in mein Programm eine Updatefunktion einbauen. Klappt auch alles super. Nach dem updaten soll das Programm gestartet werden und dann kommt die Exception. Hier mal der Code:

    .
    .
    .
            private void Completed(object sender, AsyncCompletedEventArgs e)
            {                       
                Process.Start("C:\Programme\i-was\Mein Programm.exe");    // hier kommt der Fehler her       
            }
    
            private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
            {
                progressBar1.Value = e.ProgressPercentage;
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                WebClient webClient = new WebClient();
                webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
                webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
                webClient.DownloadFileAsync(new Uri("http://website/Mein Programm.exe"), "C:\Programme\i-was\Mein Programm.exe");       // Downloaden und so tut er 
            }
    .
    .
    .
    
    static class Program
        {
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1()); // hier kommt die Exception ( TargetInvocationException was unhandlet - Ein Aufrufziel hat einen Ausnahmefehler verursacht.)
            }
        }
    

    Danke schonmal im v or ra us.



  • dann wird wohl was in

    new Form1();
    

    schief laufen



  • Ja bei der neuen Form die geöffnet wird? Aber da kam noch nie eine Exception oda sowas. Normales starten der anderen form geht ja auch ohne Probleme. ( grad auch noch mit ner bat datei verusch da kommt auch die exception).



  • Bei einer TargetInvocationException mußt du dir die 'InnerException' anschauen.



  • Backslashes besser immer escapen:

    Process.Start("C:\\Programme\\i-was\\Mein Programm.exe");
    

    oder:

    Process.Start(@"C:\Programme\i-was\Mein Programm.exe");
    


  • geeky schrieb:

    Backslashes besser immer escapen:

    Process.Start("C:\\Programme\\i-was\\Mein Programm.exe");
    

    oder:

    Process.Start(@"C:\Programme\i-was\Mein Programm.exe");
    

    thx hat geholfen 🙂 aber warum eig? Warum kann deswegen so en Fehler kommen?



  • In der InnerException der TargetInvocationException wird sich wohl ne FileNotFound-Exception versteckt haben 😉

    Falls Visual Studio - Tipp: Debug -> Exceptions und dort in der "Thrown"-Spalte Harken verteilen



  • geeky schrieb:

    In der InnerException der TargetInvocationException wird sich wohl ne FileNotFound-Exception versteckt haben 😉

    Falls Visual Studio - Tipp: Debug -> Exceptions und dort in der "Thrown"-Spalte Harken verteilen

    ja 😉 da hat sich ne FIleNotFound-Exception eingeschlichen ^^ thx



  • Hatte dein Compiler das so durch gelassen? Kann ich mir nicht vorstellen, da hättest du ein Compile Error bekommen müssen.



  • Wieso compilerfehler??


Anmelden zum Antworten