Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Binway
Helper II
Helper II

Embedded Lab cannot convert from string to system.guid

I am following some lab content I found that demonstrates how to embed Power BI content into a web app.  The PDfs are fairly straightforward but when I go to debug the code I get an error in the PBIEmbeddedManager.cs file that says "cannot convert from string to system.guid."

It is in relation to this line in the public class PbiEmbeddedManager:

private static readonly string workspaceId = ConfigurationManager.AppSettings["app-workspace-id"];

The code is picking the id up from the Web.config file which has the workspaceid from the url as instructed in the notes.  Unfortunately I have no idea how to alter the variable to a GUID or where to put it in the code.  It seems I need to add another class?? but I am not certain.

Thanks in advance.

 

1 ACCEPTED SOLUTION
Binway
Helper II
Helper II

Got it working.

Had to add a bit of extra to the code supplied in git to some classes as per below:

      /* renamed the variable to indicate it is a string for workspaceId and reportId*/
        private static readonly string strworkspaceId = ConfigurationManager.AppSettings["app-workspace-id"];
        private static string datasetId = ConfigurationManager.AppSettings["dataset-id"];
        private static readonly string strreportId = ConfigurationManager.AppSettings["report-id"];

Then in this class

  public static async Task<ReportEmbeddingData> GetReportEmbeddingData()
        {

            PowerBIClient pbiClient = GetPowerBiClient();
            /* in this class add the conversion to GUID*/
            Guid workspaceId = Guid.Parse(strworkspaceId);
            Guid reportId = Guid.Parse(strreportId);

            var report = await pbiClient.Reports.GetReportInGroupAsync(workspaceId, reportId);
            var embedUrl = report.EmbedUrl;
            var reportName = report.Name;

But in here it has to go back to string in the GUID("D") format

  return new ReportEmbeddingData
            {
                /*in here converted the GUID back to string*/
                reportId = reportId.ToString("D"),
                reportName = reportName,

With the report working.

Report.PNG

View solution in original post

1 REPLY 1
Binway
Helper II
Helper II

Got it working.

Had to add a bit of extra to the code supplied in git to some classes as per below:

      /* renamed the variable to indicate it is a string for workspaceId and reportId*/
        private static readonly string strworkspaceId = ConfigurationManager.AppSettings["app-workspace-id"];
        private static string datasetId = ConfigurationManager.AppSettings["dataset-id"];
        private static readonly string strreportId = ConfigurationManager.AppSettings["report-id"];

Then in this class

  public static async Task<ReportEmbeddingData> GetReportEmbeddingData()
        {

            PowerBIClient pbiClient = GetPowerBiClient();
            /* in this class add the conversion to GUID*/
            Guid workspaceId = Guid.Parse(strworkspaceId);
            Guid reportId = Guid.Parse(strreportId);

            var report = await pbiClient.Reports.GetReportInGroupAsync(workspaceId, reportId);
            var embedUrl = report.EmbedUrl;
            var reportName = report.Name;

But in here it has to go back to string in the GUID("D") format

  return new ReportEmbeddingData
            {
                /*in here converted the GUID back to string*/
                reportId = reportId.ToString("D"),
                reportName = reportName,

With the report working.

Report.PNG

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.