【问题标题】:The report definition is not valid. Details: The report definition has an invalid target namespace报告定义无效。详细信息:报表定义的目标命名空间无效
【发布时间】: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


【解决方案1】:

许多人通过告诉人们编辑旧 RDLC 报告的标题来回答这个问题的各种排列。这是一个可怕的想法。通常,出现此问题是因为您使用的 Microsoft.ReportingServices.ReportViewerControl.WebForms dll 版本与您尝试运行报告的 Sql Server/Sql server lite 不兼容,原因如下:

  1. 正在升级 Visual Studio 版本并使用较新的报表模板和较旧的 .dll
  2. 从某人使用旧版本 .dll 开发的存储库中提取代码,并且您正在新版本的 Visual Studio 中对其进行编辑

解决办法是通过nuget升级.dll的版本。 Visual Studio 2017 需要版本 140.xxx.xx(与 Sql Server 2016 和以前的版本兼容)。寻找Microsoft.ReportingServices.ReportViewerControl.WebForms.140.340.80

【讨论】:

    【解决方案2】:

    这两个选项对我有用:

    1. 从项目中排除报告。然后将其包含回来
    2. 重新创建报表,复制其设计代码并保存

    我开始看到一些隐藏的设计错误没有出现,我想是因为我正在处理一个非常大的项目,所以有些错误可能需要一段时间才能出现(VS2010)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-13
      • 2013-03-18
      • 1970-01-01
      • 2017-10-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多