1

I'm trying to get some ListItems out of SPO using the following code:

using Microsoft.Graph;
using Microsoft.Graph.Core;
using Microsoft.Graph.Auth;
using Newtonsoft.Json;
using System;
using System.Security.Principal;
using System.Threading.Tasks;
using Microsoft.Identity.Client;
using System.Collections.Generic;

namespace TPO_List_Access_Using_Graph_SDK
{
    class Program
    {
        static void Main(string[] args)
        {
            AsyncMain().GetAwaiter().GetResult();
            Console.Read();
        }

        static async Task AsyncMain()
        {
            IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
                .Create("...")
                .WithTenantId("...")
                .WithClientSecret("...")
                .Build();
            var authProvider = new ClientCredentialProvider(confidentialClientApplication);
            var graphClient = new GraphServiceClient(authProvider);

            var queryOptions = new List<QueryOption>()
            {
                new QueryOption("expand", "fields(select=Start,Ende)")
            };

            IListItemsCollectionPage items = await graphClient
                .Sites["pubt.sharepoint.com:/sites/leistungserfassung:"]
                .Lists["Leistungen"]
                .Items
                .Request()
                .Expand("fields")
                .GetAsync();
            
            
            Console.WriteLine(items);
            Console.WriteLine();
            Console.Read();
        }
    }
}

If I try to run the code an exception is raised:

System.NotSupportedException
The collection type 'Microsoft.Graph.IListItemsCollectionPage' on 'Microsoft.Graph.ListItemsCollectionResponse.Value' is not supported.

I'm using .net core 3.1 and the following Packages, so here's the .csproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <RootNamespace>TPO_List_Access_Using_Graph_SDK</RootNamespace>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Graph" Version="3.8.0" />
    <PackageReference Include="Microsoft.Graph.Auth" Version="1.0.0-preview.5" />
    <PackageReference Include="Microsoft.Graph.Core" Version="2.0.0-preview.3" />
    <PackageReference Include="Microsoft.Identity.Client" Version="4.15.0" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
    <PackageReference Include="System.Security.Principal" Version="4.3.0" />
  </ItemGroup>

</Project>

In Graph Explorer I tried to send the following Request, which succeeded:

GET https://graph.microsoft.com/v1.0/sites/pubt.sharepoint.com:/sites/leistungserfassung:/lists/Leistungen/items?$expand=fields

What's going wrong in my case?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Thomas Poth
  • 73
  • 1
  • 4

0 Answers0