One or more parameters required to run the report have not been specified

13,926

Solution 1

i just discovered if you pass parameter value as empty string like parameter = "" it will give you that error

took me a while

Solution 2

Allow null in parameter properties will resolve this issue.

Solution 3

Cause : Local report doesn't allow you to pass empty or null parameters it I don't know why but it throws exception.

Fix : One way to find out which parameter cause the Exception is call var result = report.LocalReport.GetParameters(); method, in result array of parameters it has result[0].State property, if it's value MissingValidValue it causes the Exception.

Example:

 var rv = new ReportViewer { ProcessingMode = ProcessingMode.Local };
        rv.LocalReport.ReportPath = Server.MapPath("~/PrintForms/FromForm.rdlc");
        rv.LocalReport.Refresh();

        string mimeType;
        string encoding;
        string filenameExtension;
        string[] streamids;
        Warning[] warnings;

        rv.LocalReport.SetParameters(new ReportParameter("ClientName", "გიორგი გიორგაძე"));
        rv.LocalReport.SetParameters(new ReportParameter("Account", "888"));var streamBytes = rv.LocalReport.Render("PDF", null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings);
        return File(streamBytes, mimeType);

Code above works fine, but if you change parameter adding line to :

rv.LocalReport.SetParameters(new ReportParameter("Account", null));

Account ReportParameter's State value would be MissingValidValue and it would cause the Exception .

Solution 4

If you really need to pass a blank string as value, you can do the folowing:

  • open Parameter Properties (right click your parameter on Report Data panel);
  • mark the Allow blank value ("") checkbox.

This solved things for me.

Share:
13,926
mrtaikandi
Author by

mrtaikandi

Updated on June 13, 2022

Comments

  • mrtaikandi
    mrtaikandi about 2 years

    I'm trying to print a RDLC file directly without showing Microsoft Report Viewer, I have followed the MSDN's example but now, every time I call the "Render" method of my instance of LocalReport class it throws the "One or more parameters required to run the report have not been specified." exception.

    Can anyone tell me which parameter is required that I missed? or how can I find more detail about this exception?

            LocalReport report = new LocalReport();
            report.ReportPath = System.Windows.Forms.Application.StartupPath + "\\" + rdlcFileName;
            report.EnableExternalImages = true;
    
            ReportParameter[] reportParams = new ReportParameter[]
            {
                new ReportParameter("LogoAddress", settings.LogoFileName),
                new ReportParameter("FooterValue", settings.InvoicesFooter)
            };
            report.SetParameters(reportParams);
    
            report.DataSources.Add(new ReportDataSource("Invoice", new PrintableInvoice[] { invoice }));
            report.DataSources.Add(new ReportDataSource("InvoiceItem", invoiceItems));
    
            Warning[] warnings;
            try
            {
                string deviceInfo =
                    "<DeviceInfo>" +
                    "  <OutputFormat>EMF</OutputFormat>" +
                    "  <PageWidth>8.5in</PageWidth>" +
                    "  <PageHeight>11in</PageHeight>" +
                    "  <MarginTop>0.25in</MarginTop>" +
                    "  <MarginLeft>0.25in</MarginLeft>" +
                    "  <MarginRight>0.25in</MarginRight>" +
                    "  <MarginBottom>0.25in</MarginBottom>" +
                    "</DeviceInfo>";
    
                m_streams = new List<Stream>();
                report.Render("Image", deviceInfo, _CreateStream, out warnings);
    
                foreach( Stream stream in m_streams )
                    stream.Position = 0;
            }
            catch( Exception ex )
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
    

    and the _CreateStream is:

        private Stream _CreateStream(string name, string fileNameExtension, Encoding encoding, string mimeType, bool willSeek)
        {
            Stream stream = new FileStream(name + "." + fileNameExtension, FileMode.Create);
            m_streams.Add(stream);
            return stream;
        }
    
  • Johny Skovdal
    Johny Skovdal over 11 years
    Thanks! That would have taken me ages to figure out probably. :) (just got the exact same error)
  • dyrssen
    dyrssen over 6 years
    This should be the accepted answer, it actually offers a solution.