Azure Functions:C# 编译错误 System.Linq.Expressions

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

我有一个 Azure 函数,负责连接到 Azure AD 并检索一些 Azure AD 信息。

当我在 .Users 上使用 .Expand() 属性 时,我收到以下编译错误:

   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

我已经正确添加了命名空间,也尝试在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"
   }
  }
 }
}

使用 C# 的 Azure Functions 解决方案中 Linq.Expressions 是否存在已知问题?

A​​zure Functions 中 Linq.Expressions 没有问题。

使用 Linq.Expression 的 HttpTriggerCSSSharp 工作示例:

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 == "admin@testdomain.onmicrosoft.com").ExecuteSingleAsync().Result;

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

}

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