【问题标题】:Unable to connect to Azure Analysis Services via Azure Function App - Could not load type 'System.Security.Principal.WindowsImpersonationContext'无法通过 Azure Function App 连接到 Azure 分析服务 - 无法加载类型“System.Security.Principal.WindowsImpersonationContext”
【发布时间】:2018-11-12 15:21:04
【问题描述】:

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

我在这里错过了什么?


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

【问题讨论】:

  • 查看我的最新更新,如果连接成功,您可以忽略这些警告。

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


【解决方案1】:

本教程适用于针对 .Net Framework 的运行时 ~1 上的函数。虽然现在 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安装。

【讨论】:

  • 在 .Net Core 运行时 ~2 上复制此功能需要进行哪些更改?
  • @iamdave 可能只是放弃使用这些程序集并找到其他方法进行身份验证,例如rest api。在内部,这些程序集试图找到 .net core env 中不可用的引用,这不仅仅是 Azure 功能问题。
  • 寻找其他验证方法 - 比如?如果不使用教程中引用的表格 DLL,还应该如何连接到 Azure 表格模型?
  • 另外,更改为 runtime ~1 会导致一堆缺少引用的错误,所以我假设这不是这里的实际问题
  • @iamdave 如果您想继续使用〜1,您能否提供那些缺失的错误以便我提供帮助?在我这边,我被 asSrv.Connect(connStr) 阻止了一些身份验证问题,因为我设置了多个身份验证因素并且无法直接登录,所以我认为 runtime ~1 可以为你工作。如果您想使用 ~2 运行时,您可以在该教程中尝试 other packages
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-12-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-14
  • 1970-01-01
  • 2019-02-12
相关资源
最近更新 更多