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

时间:2018-11-12 15:21:04

标签: c# azure ssas azure-functions azure-analysis-services

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

#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,无论我如何尝试格式化或检索此连接字符串,它都会抛出上述错误,或者抱怨没有用户或密码(省略)。

我在这里想念什么?


编辑运行时〜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?

1 个答案:

答案 0 :(得分:0)

本教程适用于运行时〜1上的Function,其目标是.Net Framework。现在,默认情况下,Function应用程序处于.Net Core运行时〜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进行安装。