我有一个 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/