Azure Functions : C# compile error with System.Linq.Expressions

851 views Asked by At

I have an Azure function that is responsible for connecting to an Azure AD and retrieving some Azure AD information.

When I use the .Expand() property on the .Users , I receive the following compilation error:

   activeDirectoryClient.Users.Expand(x => x.MemberOf).ExecuteAsync().Result;

    (38,17): error CS0012: The type 'Expression<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Linq.Expressions

I have added the namespace correctly, and also tried to add it in the project.json :

{
"frameworks": {
"net46":{
  "dependencies": {
    "Microsoft.IdentityModel.Clients.ActiveDirectory": "3.13.5",
    "Microsoft.Azure.ActiveDirectory.GraphClient": "2.1.0",
    "System.Linq": "4.0.0",
    "System.Linq.Expressions": "4.0.0"
   }
  }
 }
}

Are there known issues with Linq.Expressions in Azure Functions solution using C#?

1

There are 1 answers

4
Alexey Rodionov On BEST ANSWER

There are no issues with Linq.Expressions in Azure Functions.

Working example of HttpTriggerCSSharp using Linq.Expression:

project.json

{
"frameworks": {
"net46":{
  "dependencies": {
    "Microsoft.IdentityModel.Clients.ActiveDirectory": "3.13.5",
    "Microsoft.Azure.ActiveDirectory.GraphClient": "2.1.0"
   }
  }
 }
}

run.csx

#r "System.Linq.Expressions"

using System.Net;
using Microsoft.Azure.ActiveDirectory.GraphClient;
using Microsoft.IdentityModel.Clients.ActiveDirectory;

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
    log.Info("C# HTTP trigger function processed a request.");

    ActiveDirectoryClient activeDirectoryClient = new ActiveDirectoryClient(new Uri("https://graph.windows.net/" + "testdomain"),
                                                                                async () => await AcquireTokenAsyncForApplication());
    IUser user = activeDirectoryClient.Users.Where(u => u.UserPrincipalName == "[email protected]").ExecuteSingleAsync().Result;

    return req.CreateResponse(HttpStatusCode.OK, "Hello");

}

public static async Task<string> AcquireTokenAsyncForApplication()
{
    return "test";
}