Unexpected Error - Could not find a PackageSession for the given sessionID RRS feed

  • Question

  • Hello,

    I have a VBA macro that loops through table rows.

    On each row it opens a specific Excel file (in a separate instance) and refreshes all its queries, saves the file and continue to the next row.

    Sometimes an error occur.

    • The error does not happen always.
    • The error does not happen when opening the file manually
    • VBA macro continues with no problem, only the error dialog must be manually closed when the macro finishes in order to close the xlApp - which is the main problem, the error dialog is hanging there

    1. any idea how to avoid it or workaround?
    2. what exactly does the error mean according to the detail?

    Warm regards


    Dim xlApp As New Excel.Application

    For Each lr In Sheet2.ListObjects("refr").ListRows With lr.Range Dim wb As Workbook xlApp.Visible = True Set wb = xlApp.Workbooks.Open(.Cells(path).Value2) --- the error is fired right after previous line = not while refreshing but right after opening the file ....

    often I get this error:

    Error detail:

    Feedback Type:
    Frown (Error)
    Error Message:
    Could not find a PackageSession for the given sessionID.
    Stack Trace:
       at Microsoft.Mashup.Host.Document.Storage.WorkspaceStorage.GetPackageForRead(PackagePath packagePath)
       at Microsoft.Mashup.Host.Document.Storage.PackageStorageCache.Take(PackageReference packageReference)
       at Microsoft.Mashup.Host.Document.Storage.PackageStorageManager.OpenPackage(PackagePath packagePath, PackageMetadataDelta& delta)
       at Microsoft.Mashup.Host.Document.Model.Queries.InvokeWithPackageEditor[T](Nullable`1 changeReason, Func`2 action)
       at Microsoft.Mashup.Host.Document.QueryExtensions.HasParameterQueryMetadata(Query query, String indentifier)
       at Microsoft.Mashup.Host.Document.QueryExtensions.IsBinaryTypeParameterQuery(Query query)
       at Microsoft.Mashup.Client.UI.Shared.Ux.Navigator.QueriesNavigatorModelBase.SetQueryNodeProperties(WorkbookQueryTreeNode queryNode, Query query)
       at Microsoft.Mashup.Client.Excel.WorkbookQueriesNavigatorModel.SetQueryNodeProperties(WorkbookQueryTreeNode queryNode, Query query)
       at Microsoft.Mashup.Client.UI.Shared.Ux.Navigator.QueriesNavigatorModelBase.AddNewQueryNode(Query query)
       at Microsoft.Mashup.Client.UI.Shared.Ux.Navigator.QueriesNavigatorModelBase.Refresh()
       at Microsoft.Mashup.Client.UI.Shared.Ux.Navigator.QueriesNavigatorModelBase.LoadFromQueries(Queries queries)
       at Microsoft.Mashup.Client.Excel.TaskPaneControls.QueriesTaskPaneControlBase.SetActiveWorkbookQueries(Queries queries)
       at Microsoft.Mashup.Client.Excel.CustomTaskPaneManagers.UpdateQueriesTaskPaneVisibility(IWindowContext windowContext)
       at Microsoft.Mashup.Client.Excel.ExcelEventHandler.PerformPeriodicUpdate(IEnumerable`1 queriesTaskPaneVisibilityUpdateWindows)
       at Microsoft.Mashup.Client.Excel.NativeEventHandler.<OnIdle>b__11_0()
       at Microsoft.Mashup.Host.Document.ExceptionHandlerExtensions.HandleExceptions(IExceptionHandler exceptionHandler, Action action)
    Stack Trace Message:
    Could not find a PackageSession for the given sessionID.
    Invocation Stack Trace:
       at Microsoft.Mashup.Host.Document.ExceptionExtensions.GetCurrentInvocationStackTrace()
       at Microsoft.Mashup.Client.UI.Shared.StackTraceInfo..ctor(String exceptionStackTrace, String invocationStackTrace, String exceptionMessage)
       at Microsoft.Mashup.Client.UI.Shared.FeedbackErrorInfo..ctor(String message, Exception exception, Nullable`1 stackTraceInfo, String messageDetail)
       at Microsoft.Mashup.Client.Excel.Native.NativeUserFeedbackServices.ReportException(IWindowHandle activeWindow, IUIHost uiHost, FeedbackPackageInfo feedbackPackageInfo, Exception e, Boolean useGDICapture)
       at Microsoft.Mashup.Client.UI.Shared.UnexpectedExceptionHandler.<>c__DisplayClass14_0.<HandleException>b__0()
       at Microsoft.Mashup.Host.Document.SynchronizationContextExtensions.SendAndMarshalExceptions(SynchronizationContext context, Action callback)
       at Microsoft.Mashup.Client.UI.Shared.UnexpectedExceptionHandler.HandleException(Exception e)
       at Microsoft.Mashup.Host.Document.ExceptionHandlerExtensions.HandleExceptions(IExceptionHandler exceptionHandler, Action action)
       at Microsoft.Mashup.Client.Excel.NativeEventHandler.OnIdle()
       at Microsoft.Mashup.Client.Excel.NativeExcelConnectorBase.<OnIdleCallback>b__83_0()
       at Microsoft.Mashup.Client.Excel.ExcelCallbackManager.InvokeAndReturnHResult(Action action)
       at Microsoft.Mashup.Client.Excel.NativeExcelConnectorBase.OnIdleCallback()
    Supports Premium Content:

    • Edited by jakub dusek Saturday, March 23, 2019 10:05 PM
    Friday, March 22, 2019 12:21 PM


All replies

  • I think there is vba to pause execution until the queries have been refreshed. Maybe something like Application.CalculationState = xlDone Maybe worth a try

    Self Service BI Expert using Power Pivot

    Saturday, March 23, 2019 9:49 PM
  • That was exactly my first thoughts!

    BUT the error is thrown right after xlApp.Workbooks.Open, not while refreshing

    I have also tried solution with wait X seconds (after opening, before refreshing and after refreshing)¨. Did not help

    What exactly does the error detail sais? Does anyone understand?

    Saturday, March 23, 2019 10:05 PM
  • Any idea?
    Friday, April 5, 2019 1:10 PM
  • This is a bug we are tracking.  If you find a consistent way to reproduce the issue that would be super helpful.



    Thursday, April 11, 2019 3:07 AM
  • I am getting the same issue that Jakub describes above. It happens every day. Any luck on finding a way to fix it? Thanks!
    Thursday, May 30, 2019 12:27 PM
  • Do you have a consistent way to reproduce the error? That would help us solve it.
    Thursday, May 30, 2019 4:15 PM
  • Still no way to 100% reproduce this :(

     Fortunately macros are not affected by this and continue to run. The problem is that while the message is shown the Excel Application cannot be programmatically closed and the blank Excel App still hangs there.

    I had to kill the process in order to continue other macros.

    For anyone wondering:

    hwnd = xlApp.hwnd xlApp.Quit Set xlApp = Nothing

    KillProcess (hwnd)

    Function KillProcess(hwnd As Long)
      Dim CurrentForegroundThreadID As Long
      Dim strComputer As String
      Dim objWMIService
      Dim colProcessList
      Dim objProcess
      Dim ProcIdXL As Long
      ProcIdXL = 0
      CurrentForegroundThreadID = GetWindowThreadProcessId(hwnd, ProcIdXL)
      strComputer = "."
      Set objWMIService = GetObject _
      ("winmgmts:\\" & strComputer & "\root\cimv2")
      Set colProcessList = objWMIService.ExecQuery _
        ("Select * from Win32_Process Where ProcessID =" & ProcIdXL)
      For Each objProcess In colProcessList
    End Function

    Friday, July 12, 2019 9:18 AM
  • Hello,

    Same issue.

    I can reproduce it just changing this calendar table

    tWeeks = CALENDAR(min(PBI_AnomEECC_[time_period_id]);max(PBI_AnomEECC_[time_period_id]))

    with this one:

    tWeeks = CALENDAR(min(PBI_AnomEECC_[time_period_id]);min(max(PBI_AnomEECC_[time_period_id]);TODAY()-WEEKDAY(TODAY();2)-7))

    I hope I can help.

    Sorry if it's silly.


    Thursday, July 25, 2019 2:28 PM
  • Exact same issue that happens when I work with the same excel instance for a long time (>4h). Then I need to close excel (I usually can save the file) and also have to kill another shadow excel instance with the task manager.

    Sadly I cannot reproduce it. It happens about once a day for me.

    Thursday, July 25, 2019 6:26 PM
  • Sorry Marta, I tried this, and it didn't reproduce for me.
    Monday, August 5, 2019 9:18 PM