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

0

Following this guide, I have created an Azure Function App that compiles and runs:

#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}"); 
}

When running the function however, an exception is thrown when it tries to connect to the server object held within the asSrv variable:

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)

The connection string has the User ID and Password set as per the example and no matter how I try formatting or retrieving this connection string it either throws the above error or complains that there isn't a user or password where omitted.

What am I missing here?


Edit for Runtime ~1:

Currently getting many instances of the following error message:

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
asked on Stack Overflow Nov 12, 2018 by iamdave • edited Nov 13, 2018 by iamdave

1 Answer

1

The tutorial is for Function on runtime ~1 which targets at .Net Framework. While right now Function app is on .Net Core runtime ~2 by default.

Go to Portal, Platform features> Application settings, under Application settings section, set FUNCTIONS_EXTENSION_VERSION to ~1. Note that all functions created before will be influenced.

Update

Without .Net Core SDK support, we probably can't make it work in Funtion 2.x runtime. And those warnings of missing assemblies in ~1 runtime should be harmless.

If you meet error On-Premise Gateway is required to access the data source. Please install a unified gateway for the server, please follow this tutorial to install.

answered on Stack Overflow Nov 13, 2018 by Jerry Liu • edited Nov 14, 2018 by Jerry Liu

User contributions licensed under CC BY-SA 3.0