You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET 6连接Analysis Services Tabular模型遇类型加载错误如何解决?

.NET 6连接Analysis Services Tabular模型报错解决方案

我有一个.NET 6应用程序,尝试连接存储在Analysis服务器上的Analysis Services Tabular模型,使用以下代码进行连接(运行前已将横线替换为正确的服务器名称):

using Microsoft.AnalysisServices.Tabular;

private void button1_Click(object sender, EventArgs e)
{
    var serverName = "------------";
    using var server = new Server();                        
    server.Connect($"Provider=MSOLAP; Data Source={serverName};");
}

但连接尝试失败,报错信息如下:

System.TypeLoadException: 'Could not load type 'System.Security.Principal.WindowsImpersonationContext' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.'

请问如何解决该错误?是否需要在连接字符串中设置模拟模式?


解决方法

  • 核心原因:旧版Microsoft.AnalysisServices.Tabular依赖.NET Framework专属的WindowsImpersonationContext类型,而.NET 6作为跨平台框架已移除该类型,导致加载失败。

  • 具体步骤:

    1. 替换NuGet包:卸载原有的Microsoft.AnalysisServices.Tabular,安装专为.NET Core/.NET 5+设计的Microsoft.AnalysisServices.NetCore.retail.amd64包,该包适配.NET 6环境,不会依赖过时的框架类型。
    2. 调整连接字符串:无需额外设置模拟模式,默认使用Windows身份验证时,可显式添加Integrated Security=SSPI(默认值也是这个),示例连接字符串:
      Provider=MSOLAP; Data Source={serverName}; Integrated Security=SSPI;
      
    3. 确认驱动依赖:Windows系统需安装最新的Analysis Services OLE DB Provider(MSOLAP);非Windows环境需使用兼容的跨平台OLAP驱动。
  • 注意事项:

    • 禁止混用.NET Framework版本和.NET Core版本的Analysis Services相关NuGet包,避免依赖冲突。
    • 若为WinForms应用,确保项目目标框架已正确设置为.NET 6,且NuGet包版本与框架匹配。

内容的提问来源于stack exchange,提问作者user2148983

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 08:33:09