titanium-as / TitaniumAS.Opc.Client

Open source .NET client library for OPC DA
MIT License
193 stars 94 forks source link

PowerShell: Unable to initialize OPC DA client. It should run under MTA apartment state due to CoInitializeSecurity call. #42

Open Jomme5 opened 4 years ago

Jomme5 commented 4 years ago

Try to use library in Powershell(4.x)

  1. Start powershell-console with '-mta' switch. Nevertheless, I got the error described in title when calling [TitaniumAS.Opc.Client.Bootstrap]::Initialize().
  2. In PS-console; typing: [System.Threading.Thread]::CurrentThread.GetApartmentState() gives me 'MTA'
  3. in PS-console; typing: $host.Runspace.ApartmentState gives me 'Unknown.'

Testing in C#(VS-Studio), with console-thread in MTA, does work.