The report definition is not valid. Details: The report definition has an invalid target namespace 'http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition' which cannot be upgraded.
I am using ASP.NET MVC framework. To error comes when I setparameter()
call to set the data into rdlc designing report.
viewer.LocalReport.DataSources.Add(new ReportDataSource("SaleDataSet", modelList));
This line of code executed successfully,and report has been printed.
But at below line,
viewer.LocalReport.SetParameters(parms);
error comes.
An error comes during local report processing. The report definition has an invalid target namespace.
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;
}
}
I think quickest way is to go to the Solution Explorer window, right click on your PROJECT and go to Properties. It will open the deployment window and the very last option should be TargetServerVersion that will allow you to change the Target version.
Many have answered various permutations of this question by telling people to edit headers of old RDLC reports. This is a horrible idea. Generally, this issue materializes because you are using an version of the Microsoft.ReportingServices.ReportViewerControl.WebForms
dll that is not compatible with the Sql Server/ Sql server lite that you are trying to run the report due to:
The solution is to upgrade the version of the .dll through nuget. Visual Studio 2017 requires version 140.xxx.xx (which is compatible with Sql Server 2016 and previous versions). Look for Microsoft.ReportingServices.ReportViewerControl.WebForms.140.340.80
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With