Casting Type Error

Hi,

I am using Invoke Powershell activity to Connect Teams and retrieve unassigned telephone number. But, while running the code I am facing a type casting error says:

Invoke Power Shell: Unable to cast object of type ‘Microsoft.TeamsCmdlets.Powershell.Connect.Models.PSAzureContext’ to type ‘System.Management.Automation.PSObject’.

How to import this type in UiPath Studio. Suggests some idea

Thanks,

Hi @john.mari ,
Welcome to UiPath Community.

To resolve this issue, you may need to add a reference to the assembly that contains the required type in UiPath Studio.
You can follow these steps to get the solution.

  • Open your UiPath project in UiPath Studio.
  • Navigate to the “Imports” panel on the left-hand side of the Studio interface.
  • Click the “Browse for Types” button.
  • In the search box, type “Microsoft.TeamsCmdlets.Powershell.Connect.Models.PSAzureContext” and press Enter.
  • Select the desired assembly containing the type from the search results and click “OK”.
  • Save your changes.

If this helps you, please mark it as a solution :writing_hand:
Happy Automation :grinning:

Regards,
@pratik.maskar

I tried the method you suggested, but the namespace not showing under the import

Hi @john.mari ,

If you are not able to find the necessary module or namespace when trying to import it in UiPath Studio, it’s possible that the module is not installed on your system, or that it is not available in the default PowerShell repository.
If the necessary module is not installed, you can try installing it using the `Install-Module command in PowerShell

Regards,
@pratik.maskar

We already installed the Microsoft-Teams module using PowerShell.

Is this the “imports” tab you are referring to, Pratik?

Also @john.mari , did you managed to solve this? I’m also suffering from it…

The error doesn’t indicate that anything is missing. The error is pretty clear - somewhere there is a value of one type trying to be assigned to a value of another type.

If you do think so, you could be a little bit more useful by helping us to identify that supposed assignation.

No, there’s no value assignation anywhere whatsoever.

By the way, I managed to change the error message if I change the “TypeArgument” property from the properties tab, to that one selected there instead of “System.Management.Automation.PSObject”, yet there’s no “Microsoft.TeamsCmdlets.Powershell.Connect.Models.PSAzureContext” type I could select there.

There’s your assign. That property determines the datatype of the currentItem variable, which later affects assigning or using values.

Do you have Azure activities inside the For Each? Show them and what you have configured.

Nobody is replying to the specific error. We need to be able to make either the PSAzureContext or other types for accessing the return value of the calls to Powersell Teams connector. The calls themselves are working, but I cannot pick up the return values because the object type they use is no available on UiPath. And noone is willing to say how to set up that, if possible.

Apart from that, infering what the proper assembly is is also difficult. For instance, when using

New-Team (MicrosoftTeamsPowerShell) | Microsoft Learn

to set up a new Team, after this is done (and I already accomplished that in UiPath), I need to retrieve the GroupId, as a TeamSettings.GroupId property. But no way to find out what the TeamSettings assembly is, and how to make it available as an import on UiPath.