【发布时间】:2021-05-03 00:45:32
【问题描述】:
报告定义无效。详细信息:报告定义的目标命名空间“http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition”无效,无法升级。
我正在使用 ASP.NET MVC 框架。当我setparameter() 调用将数据设置为 rdlc 设计报告时出现错误。
viewer.LocalReport.DataSources.Add(new ReportDataSource("SaleDataSet", modelList));这行代码执行成功,报告已经打印出来了。
但在下面一行,
viewer.LocalReport.SetParameters(parms);
错误来了。
本地报告处理过程中出现错误。 报告定义的目标命名空间无效。
public ActionResult PrintSaleReport(string saleId)
{
try
{
Decimal sId = 0;
if (!string.IsNullOrEmpty(saleId))
{
sId = Convert.ToDecimal(saleId);
}
var saleList = new SaleRepository().GetById(sId);
List<SalesModel> modelList = new List<SalesModel>();
foreach (var item in saleList.SaleHistories)
{
SalesModel obj = new SalesModel();
obj.StockName = item.Stock.Name;
obj.saleQuantity = item.Quantity + "";
obj.SaleHistoryPrice = Math.Round(Convert.ToDecimal(item.SalePrice), 2) + "";
obj.Expr = Convert.ToDecimal(obj.saleQuantity) * Convert.ToDecimal(obj.SaleHistoryPrice) + "";
modelList.Add(obj);
}
var TotalAmount = Math.Round(Convert.ToDecimal(saleList.TotalBill), 2);
var discount = Math.Round(Convert.ToDecimal(saleList.Discount), 2);
var invoiceNumber = DateTime.Now.ToString("dd-MMM-yyyy hh:mm tt");
var itemCount = saleList.SaleHistories.Count();
ReportParameter[] parms = new ReportParameter[1];
parms[0] = new ReportParameter("[TotalAmount]", TotalAmount + "");
//parms[1] = new ReportParameter("[Discount]", discount+"");
//parms[2] = new ReportParameter("[InvoiceId]", invoiceNumber + "");
//parms[3] = new ReportParameter("itemCount", itemCount + "");
var viewer = new ReportViewer();
string path = Path.Combine(Server.MapPath("~/Reports"), "SaleReport.rdlc");
if (System.IO.File.Exists(path))
{
viewer.LocalReport.ReportPath = path;
}
else
{
return View("Index");
}
viewer.LocalReport.SetBasePermissionsForSandboxAppDomain(new PermissionSet(PermissionState.Unrestricted));
viewer.LocalReport.DataSources.Add(new ReportDataSource("SaleDataSet", modelList));
viewer.LocalReport.SetParameters(parms);
string reportType = "PDF";
string mimeType;
string encoding;
string fileNameExtension;
Warning[] warnings;
string[] streams;
byte[] renderedBytes;
//string deviceInfo =
// "<DeviceInfo>" +
// "<OutputFormat>" + "PDF" + "</OutputFormat>" +
// "<PageWidth> 8.5in</PageWidth>" +
// "<PageHeight> 11in</PageHeight>" +
// "<MarginTop>0.5in</MarginTop>" +
// "<MarginLeft>1in</MarginLeft>" +
// "<MarginRight>1in</MarginRight>" +
// "<MarginBottom>1in</MarginBottom>" +
// "</DeviceInfo>";
renderedBytes = viewer.LocalReport.Render(
reportType,
null,
out mimeType,
out encoding,
out fileNameExtension,
out streams,
out warnings
);
return File(renderedBytes, mimeType);
}
catch (Exception ex)
{
string message = ex.Message;
string innermesasge = ex.InnerException.Message;
var moreinnerMsg = ex.InnerException.InnerException;
throw ex;
}
}
【问题讨论】:
-
您使用的是 RDL 还是 RDLC 报告?我认为您可以将报告 XML 标头设置为 2010 版本,您能否提供有问题的报告 XML 代码?
-
我在 Visual Studio 2017 上使用 rdlc 报告。viewer.LocalReport.SetParameters(parms);来电。报告定义的目标命名空间无效。
-
您可以尝试将
ReportViewer程序集更新到版本14.0.0.0,然后安装Microsoft.RdlcDesigner(VS 可能会自动将现有的 RDLC 命名空间更改为您正在使用的当前报告版本)。跨度> -
谢谢。它为我工作。问题已成功解决。
标签: asp.net-mvc