gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 08:02:19 24 4
gpt4 key购买 nike

已关注 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)

连接字符串具有按照示例设置的用户 ID密码,无论我如何尝试格式化或检索此连接字符串,它都会抛出上述错误或提示没有省略用户或密码。

我在这里缺少什么?

<小时/>

编辑运行时〜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 上的函数,其目标是 .Net Framework。目前,Function 应用程序默认运行在 .Net Core 运行时 ~2 上。

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

更新

如果没有 .Net Core SDK 支持,我们可能无法使其在 Funtion 2.x 运行时运行。那些在大约 1 个运行时中丢失程序集的警告应该是无害的。

如果遇到错误需要本地网关才能访问数据源。请为服务器安装统一网关,请关注this tutorial安装。

关于c# - 无法通过 Azure Function App 连接到 Azure Analysis Services - 无法加载类型 'System.Security.Principal.WindowsImpersonationContext',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53265161/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com