Skip to content

Sequence contains more than one element exception when publishing dataset which overwrites an existing dataset that is used by 2 reports  #139

@saviourofdp

Description

@saviourofdp

Using version 1.0.487.

If say, I publish a report, clone the report in the same workspace and then republish the original report:

$FilePath = "example.pbix"
$WorkspaceId = "..."
$report = New-PowerBIReport -Path $FilePath -WorkspaceId $WorkspaceId -ConflictAction CreateOrOverwrite
Copy-PowerBIReport -WorkspaceId $WorkspaceId -Id $report.Id -Name "example 2"
New-PowerBIReport -Path $FilePath -WorkspaceId $WorkspaceId -ConflictAction CreateOrOverwrite

I get an error from the second publish

Exception        : System.InvalidOperationException: Sequence contains more than one element
                      at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
                      at  Microsoft.PowerBI.Common.Api.Reports.ReportsClient.PostReportForWorkspace(Guid workspaceId, 
                   String reportName, String filePath, ImportConflictHandlerModeEnum nameConflict, Int32 timeout)
                      at Microsoft.PowerBI.Commands.Reports.NewPowerBIReport.ExecuteCmdlet()
                      at Microsoft.PowerBI.Commands.Common.PowerBICmdlet.ProcessRecord()
InnerException   : False
Message          : Sequence contains more than one element
StackTrace       :    at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
                      at Microsoft.PowerBI.Common.Api.Reports.ReportsClient.PostReportForWorkspace(Guid workspaceId, 
                   String reportName, String filePath, ImportConflictHandlerModeEnum nameConflict, Int32 timeout)
                      at Microsoft.PowerBI.Commands.Reports.NewPowerBIReport.ExecuteCmdlet()
                      at Microsoft.PowerBI.Commands.Common.PowerBICmdlet.ProcessRecord()
HelpLink         : 
Source           : System.Linq
ErrorDetails     : 
ErrorCategory    : WriteError: (Microsoft.PowerBI.C\u2026ts.NewPowerBIReport:NewPowerBIReport) [New-PowerBIReport], 
                   InvalidOperationException
InvocationInfo   : System.Management.Automation.InvocationInfo

Presumably from the return import.Reports.Single(); at the end of PostReportForWorkspace because there are now 2 reports in the collection

public Report PostReportForWorkspace(Guid workspaceId, string reportName, string filePath, ImportConflictHandlerModeEnum nameConflict, int timeout)
        {
            var importId = this.PostImportForWorkspace(workspaceId, reportName, filePath, nameConflict);

            Nullable<DateTime> timeoutAt = null;
            if (timeout > 0)
            {
                timeoutAt = DateTime.Now.AddSeconds(timeout);
            }

            Import import = null;
            do
            {
                import = this.GetImportForWorkspace(workspaceId: workspaceId, importId: importId);

                if (import.ImportState != "Succeeded")
                {
                    if (timeoutAt != null && DateTime.Now > timeoutAt)
                    {
                        throw new TimeoutException();
                    }
                    else
                    {
                        System.Threading.Thread.Sleep(500);
                    }
                }

            } while (import.ImportState == "Publishing");

            if (import.ImportState != "Succeeded")
            {
                throw new ImportException(importId, reportName, import.ImportState);
            }

            return import.Reports.Single();
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions