Решение состоит в том, чтобы обновить версию .dll через nuget. Для Visual Studio 2017 требуется версия 140.xxx.xx (которая совместима с Sql Server 2016 и предыдущими версиями). Искать
еление отчета недействительно. Подробности: в определении отчета указано недопустимое целевое пространство имен.http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinitionкоторый не может быть обновлен.
Я использую ASP.NET MVC Framework. Ошибка приходит, когда я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;
}
}