Page 1 of 1

The application called an interface that was marshalled for a different thread

Posted: Sun Dec 09, 2018 3:08 pm
by fsl@framiac.com
We have a ReportViewerPage that displays any user selected report. The ReportViewerPage.xaml.cs has this

Code: Select all

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    ReportViewerPageViewModel vm = this.ReportsViewModel;
    AsyncHelper.RunSync(() => vm.PrepareReportAsync());
}
ReportViewerPageViewModel.PrepareReportAsync() looks like this

Code: Select all

public async Task PrepareReportAsync()
{
    StiReport = await ReportService.GetStiReportAsync(NavigationObject.REPORT.ReportName);
    switch (NavigationObject.REPORT.ReportName)
    {
        case ReportsHelper.Invoice:
            InvoiceViewModel invoiceViewModel = new InvoiceViewModel();
            await invoiceViewModel.InitializeAsync();
            StiReport.RegBusinessObject(nameof(InvoiceViewModel), nameof(InvoiceViewModel), invoiceViewModel);
            break;
        case ReportsHelper.Jobsheet:
            JobsheetViewModel jobsheetViewModel = new JobsheetViewModel();
            jobsheetViewModel.Initialise();
            StiReport.RegBusinessObject(nameof(JobsheetViewModel), nameof(JobsheetViewModel), jobsheetViewModel);
            break;
        case ReportsHelper.Orders:
            OrdersReportViewModel ordersReportViewModel = new OrdersReportViewModel();
            ordersReportViewModel.Initialize();
            StiReport.RegBusinessObject(nameof(OrdersReportViewModel), nameof(OrdersReportViewModel), ordersReportViewModel);
            break;
        case ReportsHelper.Materials:
            MaterialsReportViewModel materialsReportViewModel = new MaterialsReportViewModel();
            materialsReportViewModel.Initialize();
            StiReport.RegBusinessObject(nameof(MaterialsReportViewModel), nameof(MaterialsReportViewModel), materialsReportViewModel);
            break;
        case ReportsHelper.SalesReceipts:
            SalesReceiptsViewModel salesReceiptsViewModel = new SalesReceiptsViewModel();
            salesReceiptsViewModel.Initialize();
            StiReport.RegBusinessObject(nameof(SalesReceiptsViewModel), nameof(SalesReceiptsViewModel), salesReceiptsViewModel);
            break;
    }
    await StiReport.RenderAsync();
}
Most reports run fine however two of the reports return the same error:
System.TypeInitializationException: 'The type initializer for 'Stimulsoft.Helper.UWP.Helpers.StiFontHelper' threw an exception.'
Exception: The application called an interface that was marshalled for a different thread.

If we call ReportViewerPageViewModel.PrepareReportAsync() from an async method like this

Code: Select all

protected override async void OnNavigatedTo(NavigationEventArgs e)
{
    ReportViewerPageViewModel vm = this.ReportsViewModel;
    await vm.PrepareReportAsync();
}
None of our reports render, but there is no error.

Either way all of our reports are properly populated with viewmodel data.

Where do we start to look? Stack trace follows.
at Stimulsoft.Helper.UWP.Helpers.StiFontHelper.GetFontSizeD(Double maxWidth, Font font, String text, Boolean wordWrap, Boolean autoScaleFontSize)
at Stimulsoft.Report.Components.StiText.GetActualSize()
at Stimulsoft.Report.Components.StiContainerHelper.CheckSize(StiComponent component)
at Stimulsoft.Report.Engine.StiContainerV2Builder.InternalRender(StiComponent masterComp)
at Stimulsoft.Report.Engine.StiEngine.InternalRenderBand(StiBand band, Boolean ignorePageBreaks, Boolean allowRenderingEvents, Boolean& isChildsEnabled)
at Stimulsoft.Report.Engine.StiEngine.RenderBand(StiBand band, Boolean ignorePageBreaks, Boolean allowRenderingEvents)
at Stimulsoft.Report.Engine.StiStaticBandsHelper.RenderPageHeaderBands()
at Stimulsoft.Report.Engine.StiStaticBandsHelper.RenderHeaderBeforeTitle()
at Stimulsoft.Report.Engine.StiStaticBandsHelper.Render()
at Stimulsoft.Report.Engine.StiEngine.NewList(Boolean skipStaticBands)
at Stimulsoft.Report.Engine.StiEngine.NewPage(Boolean ignoreKeepContainers)
at Stimulsoft.Report.Engine.StiRenderProviderV2.RenderReport(StiReport report, StiReport masterReport, StiRenderState state)
at Stimulsoft.Report.Engine.StiRenderProviderV2.Render(StiReport report, StiRenderState state)
at Stimulsoft.Report.Engine.StiReportV2Builder.RenderSingleReport(StiReport masterReport, StiRenderState renderState)
at Stimulsoft.Report.StiReport.RenderReport(StiRenderState renderState)
at Stimulsoft.Report.StiReport.<RenderAsync>d__139.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at U2WP.ViewModels.ReportViewerPageViewModel.<PrepareReportAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Shared.Helpers.AsyncHelper.RunSync(Func`1 func)
at U2WP.Views.ReportViewerPage.OnNavigatedTo(NavigationEventArgs e)

Re: The application called an interface that was marshalled for a different thread

Posted: Mon Dec 10, 2018 7:18 am
by Lech Kulikowski
Hello,

Please send us a simple project which reproduces the issue for analysis.

Thank you.

Re: The application called an interface that was marshalled for a different thread

Posted: Fri Dec 14, 2018 6:29 pm
by fsl@framiac.com
It looks like a 3rd party service we recently introduced might have triggered the issue. We've rolled back to a previous state and reports now print as expected.

If the issue recurs I'll prepare sample project.

Re: The application called an interface that was marshalled for a different thread

Posted: Sat Dec 15, 2018 3:16 am
by Andrew
Hello,

Ok, thank you very much for the reply.
Do not hesitate to contact us if you have questions.

Thank you.