在asp net核心mvc中使用调试模式时,索引超出了数组错误的范围,但在非调试模式(Shift+F5)中运行时,索引是可以的。
在这里,错误描述的细节:
处理请求时发生了未处理的异常。IndexOutOfRangeException:索引超出了数组的界限。AspNetCore.ReportingServices.RdlExpressions.ExpressionHostObjectModel.RemoteArrayWrapper.get_Item(int指数
ReportProcessingException:报表处理中发生意外错误。索引超出了数组的界限。AspNetCore.ReportingServices.ReportProcessing.Execution.RenderReport.Execute(IRenderingExtension newRenderer)
LocalProcessingException:在本地报表处理期间发生错误。在报表处理中发生意外错误。索引超出了数组的界限。AspNetCore.Reporting.InternalLocalReport.InternalRender(string格式,bool allowInternalRenderers,string deviceInfo,PageCountMode pageCountMode,CreateAndRegisterStream createStreamCallback,out Warning[]警告)
在这里,我导出到pdf代码:
int extension = 1;
            var path = $"{this._webHostEnvironment.WebRootPath}\\Report\\RptDO2.rdlc";
            Dictionary<string, string> parameters = new Dictionary<string, string>();
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            Encoding.GetEncoding("windows-1252");
            parameters.Add("txtto", inv.Quotation.CustomerContact.Customer.CompanyName);
            parameters.Add("txtaddress_detail", inv.Quotation.CustomerContact.Customer.Address1 + "\r\n"
                + inv.Quotation.CustomerContact.Customer.Address2 + "- "
                + inv.Quotation.CustomerContact.Customer.City + "- "
                + inv.Quotation.CustomerContact.Customer.State + " ("
                + inv.Quotation.CustomerContact.Customer.Zip + ")\r\n"
                + "Phone : " + inv.Quotation.CustomerContact.Customer.PhoneNumber
                + ", Email : " + inv.Quotation.CustomerContact.Customer.Email);
            parameters.Add("txtdo_no", inv.Id.Replace("INV", "DO"));
            parameters.Add("txtdate", inv.Quotation.CreatedAt.ToShortDateString());
            parameters.Add("txtrefnum", inv.QuotationId);
            parameters.Add("txtfrom", us.FirstName + " " + us.LastName);
            parameters.Add("txtUP", TextUp);
            parameters.Add("kop_nama", c.CpName);
            parameters.Add("kop_alamat", c.CpStreetAddress);
            parameters.Add("kop_alamat2", c.CpCity + " " + c.CpState + " (" + c.CpZip + ")");
            parameters.Add("kop_contact", c.CpPhone);
            parameters.Add("kop_email", c.CpEmail);
            parameters.Add("kop_logo", Convert.ToBase64String(c.CpFoto));
            parameters.Add("txtjabatan", us.Designation);
            parameters.Add("txtPrintedBy", lgnuser.FirstName + " " + lgnuser.LastName);
            List<vwQuotationDetail> vwQuotationDetails = new List<vwQuotationDetail>();
            foreach (TblquotationDetail quos in inv.Quotation.TblquotationDetail.OrderBy(o => o.Id))
            {
                vwQuotationDetail quotationDetail = new vwQuotationDetail
                {
                    id = quos.Id,
                    quotation_id = quos.QuotationId,
                    order_number = quos.OrderNumber,
                    product_name = quos.Product.ProductName,
                    product_id = quos.ProductId,
                    product_comments = string.IsNullOrEmpty(quos.ProductComments) ? "" : quos.ProductComments,
                    quantity = quos.Quantity,
                    unit_price = quos.UnitPrice,
                    unit_name = quos.Product.Unit.UnitName,
                    sub_total = quos.SubTotal,
                    product_desc = quos.Product.ProductDesc,
                    category_name = quos.Product.Category.CategoryName
                };
                vwQuotationDetails.Add(quotationDetail);
            }
                       
            LocalReport localReport = new LocalReport(path);
            localReport.AddDataSource("dsDO", vwQuotationDetails.ToArray());
            //var result = localReport.Execute(RenderType.Pdf, extension, parameters, mimtype);
            var result = localReport.Execute(RenderType.Pdf, extension, parameters);
            return File(result.MainStream, "application/pdf");任何建议都将不胜感激,谢谢。
发布于 2021-12-13 08:05:50
只是不要将扩展名传递为1 in:
  var result = localReport.Execute(RenderType.Pdf, extension, parameters);解决办法是:
  int ext = (int)(DateTime.Now.Ticks >> 10);
  var result = localReport.Execute(RenderType.Pdf, ext, param);换言之,延期不应适用于每一份报告。
https://stackoverflow.com/questions/67830163
复制相似问题