Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with add channel to Microsoft Team (C# code, cast channel type to interface)

i have a application in Microsoft teams, and i want add channel from Visual Studio (c#). In the examples in the documentation, we can see this lines:

Channels = (ITeamChannelsCollectionPage)new List<Channel>()
{
    new Channel
    {
        DisplayName = "Class Announcements ",
        IsFavoriteByDefault = true
    },
    new Channel
    {
        DisplayName = "Homework ",
        IsFavoriteByDefault = true
    }
},

But if i try do that in Visual Studio i get a InvalidCastExeption

exeption

my code and Example code are equal

i think the SDK(Microsoft Graph) was updated, but documentation - not

My Microsoft.Graph SDK version - 3.9.0

PS. problem with cast type "Channel" to interface "ITeamChannelsCollectionPage"

like image 706
Mooonah Avatar asked Jan 25 '26 23:01

Mooonah


1 Answers

So the documentation there is completely wrong - you cannot cast like that. The correct way to use the Graph SDK is like this:

var team = new Team
{
    Channels = new TeamChannelsCollectionPage
    {
        new Channel
        {
            DisplayName = "Class Announcements"
        },
        new Channel
        {
            DisplayName = "Homework "
        }
    }
}

Note: The IsFavoriteByDefault property does not exist, it was perhaps valid in an older version of the SDK.

like image 134
DavidG Avatar answered Jan 28 '26 12:01

DavidG