0

I have a error in my wpf project. When I want make a new from MainWindow in The following code:

public App()
{
    System.Windows.Forms.Application.EnableVisualStyles();
    System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
    if (MyServer.IsAdministrator())
    {
        if (MyServer.IsRun())
            Process.GetCurrentProcess().Kill();
        else
        {
            MainWindow ObjMain = new MainWindow();
            ObjMain.Show();
        }
    }
    else
    {
        new CheckRunAsAdministrator().ShowDialog();
        Process.GetCurrentProcess().Kill();
    }
}

I see:

An unhandled exception of type 'System.InvalidOperationException' occurred in PresentationCore.dll Additional information: The calling thread must be STA, because many UI components require this.

But after this error I remove codes in App() and in App.xaml wrote

But I see another problem. Please see the below.

A first chance exception of type 'System.NotImplementedException' occurred in PresentationFramework.dll

Additional information: The method or operation is not implemented.

and after that:

An unhandled exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll

Additional information: The method or operation is not implemented.

what's the problem?

daniele3004
  • 13,072
  • 12
  • 67
  • 75
Amin
  • 387
  • 1
  • 6
  • 17
  • The problem is probably in the construction of the window or one of its controls. Debug, find the line that fails. – Emond Oct 13 '14 at 14:49
  • Where is your main wait loop? Where is your `Main` method? Do you really want to try and make WPF run without STA threads, or do you not know how to make an STA Thread? Is this a mixed Winform and WPF project? Are you using the WPF Application object somewhere? – Brannon Oct 13 '14 at 14:52
  • You should tag language, in this case c#? – crashmstr Oct 13 '14 at 15:14
  • this is a WPF Project that mixed with Several forms. – Amin Oct 13 '14 at 15:47
  • You should probably use WPF Winforms Interoperability to mix the two. This link can start you off: https://www.simple-talk.com/dotnet/.net-framework/mixing-wpf-and-winforms/ – o_weisman Dec 14 '14 at 10:37

0 Answers0