首页 > 解决方案 > 找不到方法:无效 Microsoft.PowerBI.Api.V2.PowerBIClient..ctor - Power BI Embedded

问题描述

我在使用 Power BI Embedded 时遇到问题。我想在部分视图中嵌入 Power BI 报表。按照指南,我在控制器上创建了这些方法:

public ActionResult Report()
    {
        credential = new UserCredential(username, passwordPowerBI);
        Authorize().Wait();

        ReportEmbed myReport = new ReportEmbed();

        using (var client = new PowerBIClient(new Uri(apiUrl), tokenCredentials))
        {
            EmbedToken embedToken = client.Reports.GenerateTokenInGroup(groupId, reportID, new GenerateTokenRequest(accessLevel: "View"));
            Report report = client.Reports.GetReportInGroup(groupId, reportID);

            myReport.reportID = reportID;
            myReport.embedURL = report.EmbedUrl;
            myReport.embedToken = embedToken.Token;
        }
        return PartialView(myReport);
    }

    private static Task Authorize()
    {
        return Task.Run(async () => {
            authenticationResult = null;
            tokenCredentials = null;
            var authenticationContext = new AuthenticationContext(authorityUrl);

            authenticationResult = await authenticationContext.AcquireTokenAsync(resourceUrl, clientID, credential);

            if (authenticationResult != null)
            {
                tokenCredentials = new TokenCredentials(authenticationResult.AccessToken, "Bearer");
            }
        });
    }

在视图中,我只是尝试查看我的报告。但是应用程序会出现这个异常:

在此处输入图像描述

(抱歉,有些文字是意大利语。“Impossibile trovare il metodo”的意思是“未找到方法”)。

问题是什么?web.config 中缺少某些内容?

标签: asp.netasp.net-mvcpowerbi

解决方案


它看起来像与程序集的版本不匹配。编译时它会找到正确的程序集,而运行时它会加载旧版本的客户端。检查您的部署并确保您使用的是正确的程序集。


推荐阅读