Issues with initialization and deinitialization of C# wrapper -- SOLVED

Hello,

I’m trying C# wrapper from the latest SDK v.2.0.7 and met the following issues:

  1. Initialization doesn’t work in .Net Console applications:
    ERROR [orbbec.ni.WmfBackend] Unable to initialize COM (HRESULT 0x80010106: "Cannot change thread mode after it is set.")
  2. After that I tried .Net WPF Application. And here I found out that call Astra.Context.Terminate() hangs forever.
  3. If I omit call Astra.Context.Terminate() then application crashes during exit.

Source code of WPF application:

public partial class App : Application
{
    protected override void OnStartup(StartupEventArgs e)
    {
        base.OnStartup(e);
        Astra.Context.Initialize();
    }

    protected override void OnExit(ExitEventArgs e)
    {
        base.OnExit(e);
        Astra.Context.Terminate();      // <-- hangs here!
    }
}

Please, advise.

P.S. Environment:

  • Win 8.1 64-bit
  • .Net Framework 4.6.1
  • dll-s from bin folder of SDK v.2.0.7 (VS2013, win64) were used to run test .Net application

EDIT:
With dll-s from SDK VS2015 win64 - the same.

EDIT 2:
Sorry, with dll-s from SDK VS2015 win64 Astra.Context.Terminate() works.

Hi Andrew,

Any news about Context.Initializacion doesnt work in .net console?
I’m having the same issue, while in wpf applications it works properly.

Regards

Hello @victorsbd,

Actually, it is enough to add [STAThread] attribute to Main method:

    [STAThread]
    static void Main(string[] args)
    {
        // your code is here
    }

With such attribute everything works well.

Thank you, it is working now.

Hello Andrew, I hope you are doing well!

Do you know where can I get the C# wrapper? I only found the C++ SDK.

Thanks in advance!

There’s a DLL called “AstraDotNet.dll” that ships with the SDK

Here’s an example project:

@natel @andrew Hi , please do u have the astra SDK 2.0.15 cause iam trying to use the same link to let the Astra
work with C# but I am getting error" not avalid operation" i checked it … it says the reason is the SDK version since iam using 2.1.3 so can suggest for me some solutions