The application called an interface that was marshalled for a different thread
Posted: Sun Dec 09, 2018 3:08 pm
We have a ReportViewerPage that displays any user selected report. The ReportViewerPage.xaml.cs has this
ReportViewerPageViewModel.PrepareReportAsync() looks like this
Most reports run fine however two of the reports return the same error:
If we call ReportViewerPageViewModel.PrepareReportAsync() from an async method like this
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.
Code: Select all
protected override void OnNavigatedTo(NavigationEventArgs e)
{
ReportViewerPageViewModel vm = this.ReportsViewModel;
AsyncHelper.RunSync(() => vm.PrepareReportAsync());
}
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();
}
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();
}
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)