I am trying to generate QR code using RDLC and Asp.net Core but getting below error

126 Views Asked by At

I'm using ASP.net core 5.0 and RDLC Microsoft Report Builder.

My code:

int extension = 1;
string mimtype = $"";
var path = $"{_webHostEnvironment.WebRootPath}\\Report\\prescription.rdl";
var prescription = await _prescriptionRepo.GetPriscriptionById(id);
var imagae = GenerateQrCode("sfsdf");
var pres = _mapper.Map<GetPrescriptionForReport>(prescription);
Dictionary<string, string> parameter = new Dictionary<string, string>
{
    { "patientname", $"{prescription.Patient.FirstName} {prescription.Patient.LastName}" },
    { "prescriptionid", $"{prescription.PatientId}" },
    { "advice", $"{prescription.Note}" },
    { "doctorname", $"{prescription.DoctorFirstName} {prescription.DoctorLastName}" },
    {"image", imagae}
};        
LocalReport localReport = new LocalReport(path);
localReport.AddDataSource("DataSet1", pres.MedicineForPrescription); 
var result = localReport.Execute(RenderType.Pdf, extension, parameter, mimtype);
var foo = File(result.MainStream, "application/pdf");
foo.FileDownloadName = $"{prescription.PatientId}-{prescription.Patient.FirstName} {prescription.Patient.LastName}.pdf";
return foo;

and

private string GenerateQrCode(string qrmsg)
{
    QRCoder.QRCodeGenerator qRCodeGenerator = new QRCoder.QRCodeGenerator();
    QRCoder.QRCodeData qRCodeData = qRCodeGenerator.CreateQrCode(qrmsg, QRCoder.QRCodeGenerator.ECCLevel.Q);
    QRCoder.QRCode qRCode = new QRCoder.QRCode(qRCodeData);
    Bitmap bmp = qRCode.GetGraphic(5);
    using (Bitmap bitMap = qRCode.GetGraphic(5))
    {
        using (MemoryStream ms = new MemoryStream())
        {
            bitMap.Save(ms,ImageFormat.Png);
            var byteImage = Convert.ToBase64String(ms.ToArray());
            return byteImage;
        }
    }
}

In RDLC Report: Add parameters Name : image

then

Insert> Image > Parameter > image

when I try to load the report

I'm getting the error

AspNetCore.Reporting.LocalProcessingException: An error occurred during local report processing.;The definition of the report 'I:\DotplusWeb\HospitalAPI\HospitalAPI\wwwwroot\Report\prescription.rdl' is invalid. The Value expression for the image ‘image’ contains an error: [BC30654] 'Return' statement in a Function, Get, or Operator must return a value. ---> AspNetCore.Reporting.DefinitionInvalidException: The definition of the report 'I:\DotplusWeb\HospitalAPI\HospitalAPI\wwwwroot\Report\prescription.rdl' is invalid. The Value expression for the image ‘image’ contains an error: [BC30654] 'Return' statement in a Function, Get, or Operator must return a value. ---> AspNetCore.ReportingServices.ReportProcessing.ReportPublishingException: The Value expression for the image ‘image’ contains an error: [BC30654] 'Return' statement in a Function, Get, or Operator must return a value.

0

There are 0 best solutions below