Azure函数: C# compile error with System. Linq.Expressions

标签 azure azure-functions 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 是否存在已知问题?

最佳答案

Azure Functions 中的 Linq.Expressions 没有问题。

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

项目.json

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

运行.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 == "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0766636a6e69477362747363686a666e692968696a6e647568746861732964686a" rel="noreferrer noopener nofollow">[email protected]</a>").ExecuteSingleAsync().Result;

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

}

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

关于Azure函数: C# compile error with System. Linq.Expressions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41486620/

相关文章:

javascript - w 和 h 必须是数字

.net - 将 v1 转换为 v2 DotNetStandard 的 Azure 函数 'AzureWebJobsServiceBus' 丢失或为空

c# - 使用 Enum as/with 表达式?

azure - 错误: ENOENT: no such file or directory in visual studio code

git - Azure Function 持续部署如何处理特定于环境的转换?

asp.net-mvc-3 - windows azure ASP.NET MVC 3 上的成员身份验证 - 找不到列

如果调用时间超过 1 分钟,ServiceBus 上的 WCF 服务将失败

azure - 如何保护来自 WWW 的 Azure 网站/功能?

c# - 在转换为 "out/ref"的表达式中支持 "object"参数

c# - 如何在具有不同返回类型的 Linq 表达式之间进行转换?