c++/cli and create WPF UserControl without STA thread apartment (help) RRS feed

  • Question

  • I have project where WPF UserControl is used for GUI.

    I simply working with UserControl created in C# project inside C++/CLI

    controls = gcnew uc_control();

    The problem is, when project is compiled, it throw this error:

    Unhandled Exception: System.InvalidOperationException: The calling thread must be STA, because many UI components require this.

    this error cause code above.

    The interesting part is, when project is run under validator (validator is not created by me) then error is occurred. But when project is run under host application, everything is working, without any error.

    question is, Where should be problem? Should I use another thread with STA enabled? Is it ok create UserControl or any other C# object from WPF without STA thread?

    Tuesday, March 10, 2020 7:55 PM


All replies