Graph API throw error when trying to create an user

Abhishek Shukla 0 Reputation points Microsoft Employee
2024-06-21T01:41:15.36+00:00

Error - {The expression cannot be evaluated. A common cause of this error is attempting to pass a lambda into a delegate.}

Here is code I am using

        var requestBody = new User

        {

            AccountEnabled = true,

            DisplayName = "Display Name",

            GivenName = "Display",

            Mail = "cccccccccc@gmail.com",

            Surname = "Name",

            UserPrincipalName = "cccccccccc@gmail.com"

        };

        var result = await _appClient.Users.PostAsync(requestBody);
```I followed the tutorial here ([https://learn.microsoft.com/en-us/graph/tutorials/dotnet-app-only?tabs=aad](https://learn.microsoft.com/en-us/graph/tutorials/dotnet-app-only?tabs=aad)) and ([https://learn.microsoft.com/en-us/graph/api/user-post-users?view=graph-rest-1.0&tabs=csharp](https://learn.microsoft.com/en-us/graph/api/user-post-users?view=graph-rest-1.0&tabs=csharp)) Everything works but when I add my custom code as above, it fails with error.

 **{The expression cannot be evaluated.  A common cause of this error is attempting to pass a lambda into a delegate.}**

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,268 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Vasil Michev 99,431 Reputation points MVP
    2024-06-21T08:37:27.2266667+00:00

    You cannot use consumer ID values for the UserPrincipalName property. It needs to match a domain within your Entra tenant, i.e. ccccccccc@tenant.onmicrosoft.com

    0 comments No comments

  2. Abhishek Shukla 0 Reputation points Microsoft Employee
    2024-06-21T18:35:16.4266667+00:00

    It does not work. Even after removing the UserPrincipalName it fails.

    0 comments No comments