Search code examples
c#com-interopskype-for-businesscomobjectcom-object

Skype for Business shell commands from code



I've developed an application that manages Skype For Business users configurations.
One of the operations I need to run should set Skype user's registrar pool, using this command:

Move-CsUser -Identity [UserName] -Target [RegistrarPool] -Confirm:$false

Now when I run the command from the command line – it works great.
But, unlike the other Skype shell commands I use within my application, when I run that command using my c# code I get this terrible error:

Move-CsUser : Unable to cast COM object of type 'System.__ComObject' to interface type \r\n
'Microsoft.Rtc.Interop.User.ICsUserManagement'. This operation failed because the QueryInterface call on the COM \r\n
component for the interface with IID '{D5ADD966-BDC3-4A8F-BFE8-6A59A9F74CB2}' failed due to the following error: Class \r\n
not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).\r\nAt line:1 char:1\r\n+
Move-CsUser -Identity 'testuser' -Target 'XXX' -Confirm: ...\r\n+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\r\n    +
CategoryInfo          : InvalidOperation: (CN=Agent Develo...DC=il,DC=tleumi:OCSADUser) [Move-CsUser], InvalidCa \r\n   stException\r\n   
+ FullyQualifiedErrorId : MoveError,Microsoft.Rtc.Management.AD.Cmdlets.MoveOcsUserCmdlet\r\n \r\n"

I'm apparently terrible at overcoming COM object's errors, despite my best attempts to solve it.

Can anyone give me a hand?
How can I make it work?


Solution

  • yeah its a pain have this every time I do a lync coding project. Right click on your project name go to properties. you need to set the platform target to x64 not any cpu