lkosson / reportviewercore

Recompilation of Microsoft.ReportViewer for .NET Core 3.1+
427 stars 123 forks source link

Exception when using report viewer when publishing application into a single file. #179

Closed akertesz-permaquim closed 8 months ago

akertesz-permaquim commented 8 months ago

It has been more than a year ago when we implemented this solution in order to show Reports in a Net 6 Winforms application, however, we've been having some issues once we want to publish the actual application to a single .exe. Whenever I try to generate a report, the following exception shows:

An error occurred during local report processing. at Microsoft.Reporting.WinForms.LocalReport.EnsureExecutionSession() at Microsoft.Reporting.WinForms.LocalReport.SetParameters(IEnumerable`1 parameters) at Permaquim.Counter.UI.Desktop.Forms.FormReport.GetUpdate()

The code that is throwing the exception:

    ReportParameter[] parameters = { new("emisionUser", DatabaseController.CurrentUser.NombreApellido),
                                new("image", "file:\\" + AppDomain.CurrentDomain.BaseDirectory + @"\Reports\ReportLogo.png"),
                                new("filtrosAplicados",GetFilterString())};

    this.reportViewer.LocalReport.SetParameters(parameters);
    SelectedShifts = shiftList.CheckedItems.OfType<CComboBoxItem<Entities.Relations.Operacion.Turno>>().ToList();
    this.reportViewer.LocalReport.DataSources.Add(new("ShiftDS", reportShifts));
    reportViewer.RefreshReport();

You can view the report viewer itself, however it does fail once I try to use it in any way shape or form. This doesn't happen when I publish the project with all of its Dll files loose. Is there anything that can be done to solve this? Thanks a ton.

lkosson commented 8 months ago

Publishing to single file and/or AoT compilation won't work. #49 for details.

As a workaround, you can copy Microsoft.CodeAnalysis.VisualBasic.dll and all other missing DLLs mentioned in exception to your output directory, but then it won't really be a single file deployment.