我正在尝试使用 RDLC 和 Asp.net Core 生成 QR 码,但出现以下错误

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

提问人:MD SHAFFAT 提问时间:10/31/2023 最后编辑:James ZMD SHAFFAT 更新时间:10/31/2023 访问量:29

问:

我正在使用 ASP.net 核心 5.0 和 RDLC Microsoft报表生成器。

我的代码:

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;

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;
        }
    }
}

在 RDLC 报告中: 添加参数 名称 : image

然后

插入>图像 > 图像>参数

当我尝试加载报告时

我收到错误

AspNetCore.Reporting.LocalProcessingException:本地报表处理过程中发生错误。报告“I:\DotplusWeb\HospitalAPI\HospitalAPI\wwwwroot\Report\prescription.rdl”的定义无效。 图像“image”的 Value 表达式包含错误:[BC30654] Function、Get 或 Operator 中的“Return”语句必须返回一个值。 ---> AspNetCore.Reporting.DefinitionInvalidException:报告“I:\DotplusWeb\HospitalAPI\HospitalAPI\wwwwroot\Report\prescription.rdl”的定义无效。 图像“image”的 Value 表达式包含错误:[BC30654] Function、Get 或 Operator 中的“Return”语句必须返回一个值。---> AspNetCore.ReportingServices.ReportProcessing.ReportPublishingException:图像“image”的 Value 表达式包含错误:[BC30654] Function、Get 或 Operator 中的“Return”语句必须返回值。

.NET ASP.net-core RDLC RDL

评论


答: 暂无答案