reporting-serviceslocalreport

VS 2017 with Local reports - The report definition has not been specified


I am using vs2017 with ReportViewer 14.0 in a WinForms application. I have done this before in previous versions of VS without any issues and I am very surprised why I can't make this work this time.

Here is what I have done so far:

string path = AppDomain.CurrentDomain.BaseDirectory + @"Reports\Report.rdlc";
rpt.LocalReport.ReportPath = path;

rpt.LocalReport.SetParameters(new ReportParameter("parTitle", Title));

rpt.LocalReport.DataSources.Add(new ReportDataSource("ds", Data));
rpt.Refresh();

When I run the app, the form loads but the ReportViewer displays a message: The report definition has not been specified

I also tried setting the build action to EmbeddedResource and using:

rpt.LocalReport.ReportEmbeddedResource = "Project.Reports.Report.rdlc";

Same result. I even tried:

Assembly a = Assembly.GetExecutingAssembly();
Stream report = a.GetManifestResourceStream("Project.Reports.Report.rdlc");
rpt.LocalReport.LoadReportDefinition(report);

No difference. I am always getting this:

enter image description here

I have been staring at this for several hours now and for the life of me I cannot figure out what I am doing wrong. Any help would be greatly appreciated.

Thank you.


Solution

  • I feel quite foolish now, but just as a reference to anyone facing the same issue I am posting the solution here.

    Changing

    rpt.Refresh();

    to

    rpt.RefreshReport();

    did the trick. The report now loads properly. Refresh is inherited from Control and only invalidates the control, but does not force the report to be processed and rendered. RefreshReport does just that.

    Hope this saves some time to someone.