连接到Azure Analysis Services时出错

时间:2017-05-17 15:59:32

标签: c# adomd.net azure-analysis-services

我是azure分析服务的新手,并尝试使用AdomdClient进行查询。我从这里下载了最新的客户端库:

  

https://docs.microsoft.com/en-us/azure/analysis-services/analysis-services-data-providers

我尝试了什么:

  • 安装必要的SQL Server数据工具后,我可以从SSMS连接到模型。
  • 我能够在一个简单的WebApi中连接和查询,没有任何问题,没有使用对客户端库的引用的其他依赖
  • 当项目依赖于版本高于2.8的Microsoft.IdentityModel.Clients.ActiveDirectory
  • 时,我无法连接和查询

但是在连接到C#

中的实例时
        using (var conn 
        = new Microsoft.AnalysisServices.AdomdClient.AdomdConnection(
            ConfigurationManager.ConnectionStrings["dax"].ConnectionString))
        {
            conn.Open();

            conn.Close();
        }

我收到以下错误:

"Message": "An error has occurred.",
  "ExceptionMessage": "Authentication failed: Microsoft.IdentityModel.Clients.ActiveDirectory failed to load 'Microsoft.IdentityModel.Clients.ActiveDirectory.PromptBehavior type'.",
  "ExceptionType": "Microsoft.AnalysisServices.AdomdClient.AdomdConnectionException",
  "StackTrace": "
   at Microsoft.AnalysisServices.AdomdClient.AdalRuntimeLibrary.LoadAndValidateType(Assembly assembly, String typeName)
   at Microsoft.AnalysisServices.AdomdClient.AdalRuntimeLibrary.LoadAuthenticationContextTypes(Assembly assembly)
   at Microsoft.AnalysisServices.AdomdClient.AdalRuntimeLibrary..ctor()
   at Microsoft.AnalysisServices.AdomdClient.AdalRuntimeLibrary.get_Instance()
   at Microsoft.AnalysisServices.AdomdClient.AadAuthenticator.AcquireToken(Uri dataSourceUri, String dataSource, String identityProvider, String userId, String password, Boolean useAdalCache)
   at Microsoft.AnalysisServices.AdomdClient.XmlaClient.OpenHttpConnection(ConnectionInfo connectionInfo, Boolean& isSessionTokenNeeded)
   at Microsoft.AnalysisServices.AdomdClient.XmlaClient.OpenConnection(ConnectionInfo connectionInfo, Boolean& isSessionTokenNeeded)
   at Microsoft.AnalysisServices.AdomdClient.XmlaClient.Connect(ConnectionInfo connectionInfo, Boolean beginSession)
   at Microsoft.AnalysisServices.AdomdClient.AdomdConnection.XmlaClientProvider.Connect(Boolean toIXMLA)
   at Microsoft.AnalysisServices.AdomdClient.AdomdConnection.ConnectToXMLA(Boolean createSession, Boolean isHTTP)
   at Microsoft.AnalysisServices.AdomdClient.AdomdConnection.Open()
   at ...
  • 经过一些挖掘后,我们意识到AdomdClient dll在dll中引用了嵌入式ActiveDirectory dll,它引用了2.8版。*
  • 我无法将版本降低到Microsoft.IdentityModel.Clients.ActiveDirectory,因为我使用的少数几个nuget明确地将最低版本限制为3.x,这肯定会改变错误中出现的Microsoft.IdentityModel.Clients.ActiveDirectory.PromptBehavior

有解决方法吗?

1 个答案:

答案 0 :(得分:1)

我有一个类似的问题。我的解决方案中的其他项目引用的ActiveDirectory版本> 3.0,而AdomdClient需要的<2.8。在app.config中添加如下所示的绑定重定向可解决我的问题。这将使其他dll使用Active Directory的> 3.0版本,但AdomdClient可以使用2.8.x

      <dependentAssembly>       
        <assemblyIdentity name="Microsoft.IdentityModel.Clients.ActiveDirectory" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="3.0.0.0-3.19.8.16603" newVersion="3.19.8.16603" />
      </dependentAssembly>