Error when printing pagedocument AR 15.1.7

Posted by: mpoelen on 4 April 2022, 9:55 pm EST

    • Post Options:
    • Link

    Posted 4 April 2022, 9:55 pm EST

    Hello,

    I’m new in active reports and i am trying to print a report in a asp.net web api in .net 5. I have managed to render a report and get back as a pdf when doing a get request. When i want to print te same report i get the following exception.

    “message”: “Could not load file or assembly ‘System.Resources.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51’. The system cannot find the file specified.”,

    “type”: “System.IO.FileNotFoundException”,

    Don’t know if it has anything to doe with it but:

    When in debug mode i see that the pagedocument.IsEmpty throws an exception of type InvalidOperationException.

    Here is the used code

        /// <summary>
        /// Get all report categories.
        /// </summary>
        ///// <param name="id"></param>
        ///// <param name="queryParameterString"></param>
        /// <param name="ct"></param>
        /// <response code="200">Ok</response>
        /// <response code="400">Bad Request</response>
        /// <response code="401">Unauthorized</response>
        /// <response code="403">Forbidden</response>
        /// <response code="404">Not Found</response>
        /// <response code="500">Internal Server Error</response>
        /// <returns></returns>
        [HttpGet("print-custom")]
        //[Produces(@"application/pdf")]
        [ProducesResponseType(typeof(Stream), 200)]
        [ProducesResponseType(typeof(ValidationProblemDetails), 400)]
        [ProducesResponseType(typeof(ProblemDetails), 401)]
        [ProducesResponseType(typeof(ProblemDetails), 403)]
        [ProducesResponseType(typeof(ProblemDetails), 404)]
        [ProducesResponseType(typeof(ProblemDetails), 405)]
        [ProducesResponseType(typeof(ProblemDetails), 500)]
        public async Task<bool> PrintLabel(/*int id, string queryParameterString,*/ CancellationToken ct)
        {
          var pageReport = new PageReport();
          var xmlString = await _labelService.GetLabelScript(27, ct);
    
          var connectionString = _configuration.GetConnectionString("ConnectionString");
          
          pageReport.Run();
          var pageDocument = pageReport.GeneratePageDocument(
              xmlString, "1", false, connectionString
            );
    
          pageDocument.SetParameterValues(null);
    
          var printerSettings = new GrapeCity.ActiveReports.PrinterSettings(pageReport.Report)
          {
            ShowPrintDialog = false,
            ShowPrintProgressDialog = false,
            UsePrintingThread = false,
            UseStandardDialog = false,
            UseXpDialog = false
          };
    
          printerSettings.Printer.Landscape = true;
    
          printerSettings.Printer.PrinterName = "Microsoft Print to PDF";
    
          printerSettings.Printer.PrinterSettings.Copies = 1;
    
    
          //var r = pageDocument.IsEmpty;
    
          pageDocument.Print(printerSettings);
    
          return true;
    
          //// Code below renders the pagedocument and this works
          //Provide settings for your rendering output.
    
          //var pdfSetting = new GrapeCity.ActiveReports.Export.Pdf.Page.Settings();
    
          // // Set the rendering extension and render the report.
          // var pdfRenderingExtension = new GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension();
    
          // var outputProvider = new GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider();
    
          // pageDocument.Render(pdfRenderingExtension, outputProvider, pdfSetting);
    
          // return outputProvider.GetPrimaryStream().OpenStream();
        }
      }
    

    Extension methods used:

      internal static class GrapeCityPageReportExtensions
      {
        
        internal static PageDocument GeneratePageDocument(
          this PageReport pageReport,
          string labelScript,
          string queryParameterValue,
          bool fixPageDimUndefined,
          string connectionString)
        {
          pageReport
            .LoadString(labelScript)
            .SetQueryParameterValue(queryParameterValue)
            .DdrToAr(fixPageDimUndefined)
            .SetConnectString(connectionString);
    
          pageReport.Run();
    
          return new PageDocument(pageReport);
        }
    
        internal static PageReport LoadString(this PageReport pageReport, string labelScript)
        {
          if (pageReport == null || string.IsNullOrEmpty(labelScript))
            return pageReport;
    
          using TextReader tr = new StringReader(labelScript);
    
          pageReport.Load(tr);
    
          return pageReport;
        }
    
        internal static PageReport SetQueryParameterValue(this PageReport pageReport, string queryParameterValue)
        {
          if (pageReport == null || string.IsNullOrEmpty(queryParameterValue))
            return pageReport;
    
          var dataSet = pageReport.Report?.DataSets?.FirstOrDefault();
    
          var queryParameter = dataSet?.Query?.QueryParameters.FirstOrDefault();
    
          if (queryParameter != null)
            queryParameter.Value = queryParameterValue;
    
          return pageReport;
        }
    
        internal static PageReport DdrToAr(this PageReport pageReport, bool fixPageDimUndefined)
        {
          if (pageReport == null || !fixPageDimUndefined)
            return pageReport;
    
          if (pageReport.Report.PageHeight.IsUndefined)
            pageReport.Report.PageHeight = pageReport.Report.Body.Height;
    
          if (pageReport.Report.PageWidth.IsUndefined)
            pageReport.Report.PageWidth = pageReport.Report.Width;
    
          return pageReport;
        }
    
        internal static PageReport SetConnectString(this PageReport pageReport, string connectionString)
        {
          if (pageReport == null || string.IsNullOrEmpty(connectionString))
            return pageReport;
    
          var dataSource = pageReport.Report?.DataSources?.FirstOrDefault();
    
          if (dataSource != null)
            dataSource.ConnectionProperties.ConnectString = connectionString;
    
          return pageReport;
        }
      }
    
  • Posted 5 April 2022, 1:33 am EST

    The problem is already solved, an Package reference was missing.

  • Posted 5 April 2022, 6:37 pm EST

    Hi Mark,

    I am glad you were able to resolve your issue. Thanks for sharing the solution with us. It will help others who are doing something similar.

  • Posted 28 February 2023, 8:03 am EST

    I am having the same issue - what package did you need to add?

  • Posted 1 March 2023, 2:45 pm EST

    Hi Mike,

    This seems to be a generic issue. As per the error message the package “System.Resources.Extension” is not found. I would suggest you to try adding this package to your project and refer to the following post on the StackOverFlow Forum page:

    https://stackoverflow.com/questions/64298051/cant-load-system-resources-extensions-in-net-framework

    If the issue persists then please share a sample application reproducing this issue so we can reproduce this issue at our end and get back to you accordingly.

    Regards,

    Akshay

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels