无法通过 Azure Function App 连接到 Azure Analysis Services - 无法加载类型 'System.Security.Principal.WindowsImpersonationContext'

Unable to connect to Azure Analysis Services via Azure Function App - Could not load type 'System.Security.Principal.WindowsImpersonationContext'

按照 this 指南,我创建了一个可以编译和运行的 Azure Function App:

#r "Microsoft.AnalysisServices.Tabular.DLL"
#r "Microsoft.AnalysisServices.Core.DLL"
#r "System.Configuration"

using System;
using System.Configuration;
using Microsoft.AnalysisServices.Tabular;

// req is a value passed from function.json which is currently ignored
public static void Run(String req, ILogger log)
{
    log.LogInformation($"C# Timer trigger function started at: {DateTime.Now}");

    try
            {
                Microsoft.AnalysisServices.Tabular.Server asSrv = new Microsoft.AnalysisServices.Tabular.Server();

                // Pulls the connection string from the Connection Strings collection within the Application Settings
                //var connStr = ConfigurationManager.ConnectionStrings["AASDev"].ConnectionString;

                // Pulls the connection string from an Environment Variable held within the Application Settings collection
                //var connStr = GetEnvironmentVariable("Conn");

                // Simply hard coding the connection string (Anonymised)
                var connStr = @"Data Source=asazure://<roll out>.asazure.windows.net/<My AAS Instance>;Initial Catalog=<My AAS Database>;User ID=<My User>;Password=<My Pass>";

                asSrv.Connect(connStr);
                Database db = asSrv.Databases["<My AAS Database>"];
                Model m = db.Model;
                m.Tables["<My AAS Table>"].RequestRefresh(RefreshType.Full);     // Mark only one table for refresh
                db.Model.SaveChanges();     //commit  which will execute the refresh
                asSrv.Disconnect();
            }
            catch (Exception e)
            {
                log.LogInformation($"C# Timer trigger function exception: {e.ToString()}");
            }
    log.LogInformation($"C# Timer trigger function finished at: {DateTime.Now}"); 
}

然而,当 运行 函数尝试连接到 asSrv 变量中保存的服务器对象时会抛出异常:

2018-11-12T13:45:40.273 [Information] C# Timer trigger function exception: 
System.TypeLoadException:
  Could not load type 'System.Security.Principal.WindowsImpersonationContext' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=<removed>'.  
    at Microsoft.AnalysisServices.IdentityResolver.Dispose()  
    at Microsoft.AnalysisServices.XmlaClient.Connect(ConnectionInfo connectionInfo, Boolean beginSession)  
    at Microsoft.AnalysisServices.Core.Server.Connect(String connectionString, String sessionId, ObjectExpansion expansionType)  
    at Submission#0.Run(TimerInfo myTimer, TraceWriter log)

连接字符串按照示例设置了 User IDPassword,无论我如何尝试格式化或检索此连接字符串,它要么抛出上述错误,要么抱怨没有' t 省略的用户名或密码。

我在这里错过了什么?


为运行时编辑 ~1:

当前收到以下错误消息的多个实例:

2018-11-13T10:02:42.817 [Warning] Unable to find assembly 'Microsoft.VisualStudio, PublicKeyToken=xxx'. Are you missing a private assembly file?
2018-11-13T10:02:42.817 [Warning] Exception during runtime resolution of assembly 'Microsoft.VisualStudio, PublicKeyToken=xxx': 'System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

   at System.AppDomain.nApplyPolicy(AssemblyName an)

   at Microsoft.Azure.WebJobs.Script.Description.FunctionAssemblyLoader.ResolveAssemblyCore(Object sender, ResolveEventArgs args) in C:\projects\azure-webjobs-sdk-script\src\WebJobs.Script\Description\DotNet\FunctionAssemblyLoader.cs:line 88'
2018-11-13T10:02:42.817 [Warning] Unable to find assembly 'Microsoft.VisualStudio, PublicKeyToken=xxx'. Are you missing a private assembly file?
2018-11-13T10:02:43.676 [Warning] Unable to find assembly 'Microsoft.AnalysisServices.Tabular.resources, Version=15.0.0.0, Culture=en-US, PublicKeyToken=xxx'. Are you missing a private assembly file?
2018-11-13T10:02:43.676 [Warning] Unable to find assembly 'Microsoft.AnalysisServices.Tabular.resources, Version=15.0.0.0, Culture=en, PublicKeyToken=xxx'. Are you missing a private assembly file?

本教程针对 .Net Framework 运行时 ~1 上的函数。虽然现在 Function app 默认在 .Net Core runtime ~2 上。

转到门户、平台功能 > 应用程序设置,在应用程序设置部分下,将 FUNCTIONS_EXTENSION_VERSION 设置为 ~1。请注意,之前创建的所有功能都会受到影响。

更新

如果没有 .Net Core SDK 支持,我们可能无法使其在 Funtion 2.x 运行时运行。 ~1 运行时中缺少程序集的警告应该是无害的。

如果遇到错误On-Premise Gateway is required to access the data source. Please install a unified gateway for the server,请按照this tutorial安装。