A community member has associated this post with a similar question:
Can't use Expand to get singleValueExtendedProperties on a single email query (SDK 5.1.0)

Only moderators can edit this content.

Can't use Expand to get singleValueExtendedProperties on a single email query (SDK 5.1.0)

Steve Clarke 10 Reputation points
2023-03-15T06:46:09.0133333+00:00

Hello,

I am using the Microsoft.Graph 5.1.0 SDK in a C# project and need to get internet headers of a single email.

The issue is that to do this I need to use Expand in the query parameters, but this does not appear to exist for the Microsoft.Graph.Users.Item.Messages.Item.MessagesRequestBuilder and the attached code will therefore give you an error:

Error CS1061 'MessageItemRequestBuilder.MessageItemRequestBuilderGetQueryParameters' does not contain a definition for 'Expand' and no accessible extension method 'Expand' accepting a first argument of type 'MessageItemRequestBuilder.MessageItemRequestBuilderGetQueryParameters' could be found (are you missing a using directive or an assembly reference?)

var emails = graphServiceClient.Users[userEmail].MailFolders["sentitems"].Messages
                .GetAsync((requestConfiguration) =>
                {
                    requestConfiguration.QueryParameters.Select = selectProperties;
                    requestConfiguration.QueryParameters.Filter =
                        $"id eq {id}";
                    requestConfiguration.QueryParameters.Expand = new string[]
                    {
                        "singleValueExtendedProperties($filter=id eq 'String {00020386-0000-0000-C000-000000000046} Name x-internet-header-name')"
                    };
                    requestConfiguration.QueryParameters.Top = 1;
                })
                .Result;

I am able to successfully use Expand on queries on a mailbox, but I only want to retrieve a specific email (but it does show that Microsoft.Graph.Users.Item.MailFolders.Item.Messages.MessagesRequestBuilder is slightly different here).

I can also use Graph Explorer to retrieve this information on a single email which shows that Graph itself should be able to handle the this query.
(swap out {UserId} and {EmailId})

https://graph.microsoft.com/v1.0/Users/{UserId}/Messages/{EmailId}?$select=id,subject,singleValueExtendedProperties&$expand=singleValueExtendedProperties($filter=id eq 'String {00020386-0000-0000-C000-000000000046} Name x-internet-header-name')

Is the SDK able to have the Expand added to Microsoft.Graph.Users.Item.Messages.Item.MessagesRequestBuilder?

Thank you.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,557 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,223 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. HarmeetSingh7172 4,811 Reputation points
    2023-04-11T13:30:38.12+00:00

    Hello @Steve Clarke

    Thanks for posting!

    The CS1061 error is caused when you try to call a method or access a class member that does not exist. Refer this Compiler messages documentation.

    The following example generates CS1061 because Person does not have a DisplayName method. It does have a method that is called WriteName. Perhaps that is what the author of this source code meant to write.

    public class Person
    {
        private string _name;
    
        public Person(string name) => _name = name;
    
        // Person has one method, called WriteName.
        public void WriteName()
        {
            System.Console.WriteLine(_name);
        }
    }
    
    public class Program
    {
        public static void Main()
        {
            var p = new Person("PersonName");
    
            // The following call fails because Person does not have
            // a method called DisplayName.
            p.DisplayName(); // CS1061
        }
    }
    

    To correct this error:

    1. Make sure you typed the member name correctly.
    2. If you have access to modify this class, you can add the missing member and implement it.
    3. If you don't have access to modify this class, you can add an extension method.

    Note: Not all relationships and resources support the $expand query parameter. For example, you can expand the directReports, manager, and memberOf relationships on a user, but you cannot expand its events, messages, or photo relationships. Not all resources or relationships support using $select on expanded items.

    Refer this to know about known issues- limitations apply to query parameters.

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote. If you have any further questions about this answer, please click Comment.

    0 comments No comments