我有一个Azure功能,负责连接到Azure AD并检索一些Azure AD信息。
当我在.Expand()
上使用.Users
属性时,收到以下编译错误:
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
的已知问题?
答案 0 :(得分:0)
Azure功能中的Linq.Expressions没有问题。
使用Linq.Expression:
的HttpTriggerCSSharp的工作示例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";
}