【问题标题】:Rdlc report unable to parse regular expressionrdlc报告无法解析正则表达式
【发布时间】:2020-11-27 06:06:50
【问题描述】:

我正在使用 .net 框架 4.7.2。在一个带有Ninject 依赖注入的Web API 项目中,我正在尝试使用expression 生成一个rdlc 报告。问题是当我不使用任何表达式时报告生成完美,但使用表达式时一切都出错了。只是数据集两个字段的正常求和表达式。

=Fields!AdditionalPremiumDeposit.Value + Fields!RefundOfPremium.Value

这两个字段是数据集字段(十进制)

每当我尝试生成报告时,我都会收到错误消息,如下 ->

Failed to load expression host assembly. Details: Type 'Ninject.Web.WebApi.NinjectDependencyResolver' 
in assembly 'Ninject.Web.WebApi, Version=3.3.1.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7' 
is not marked as serializable.

堆栈跟踪 ->

   at 
  Microsoft.ReportingServices.RdlExpressions.ReportRuntime.ProcessLoadingExprHostException(Exception 
  e, ProcessingErrorCode errorCode)
  at Microsoft.ReportingServices.RdlExpressions.ReportRuntime.LoadCompiledCode(Report report, Boolean 
  includeParameters, Boolean parametersOnly, ObjectModelImpl reportObjectModel, ReportRuntimeSetup 
  runtimeSetup)
  at Microsoft.ReportingServices.OnDemandProcessing.Merge.Init(Boolean includeParameters, Boolean 
  parametersOnly)
  at Microsoft.ReportingServices.OnDemandProcessing.Merge.Init(ParameterInfoCollection parameters)
  at Microsoft.ReportingServices.ReportProcessing.ReportProcessing.ProcessOdpReport(Report report, 
  OnDemandMetadata odpMetadataFromSnapshot, ProcessingContext pc, Boolean snapshotProcessing, Boolean 
  reprocessSnapshot, Boolean processUserSortFilterEvent, Boolean processWithCachedData, ErrorContext 
  errorContext, DateTime executionTime, IChunkFactory cacheDataChunkFactory, StoreServerParameters 
  storeServerParameters, GlobalIDOwnerCollection globalIDOwnerCollection, SortFilterEventInfoMap 
  oldUserSortInformation, EventInformation newUserSortInformation, String 
  oldUserSortEventSourceUniqueName, ExecutionLogContext executionLogContext, 
  OnDemandProcessingContext& odpContext)
  at Microsoft.ReportingServices.ReportProcessing.ReportProcessing.RenderReport(IRenderingExtension 
  newRenderer, DateTime executionTimeStamp, ProcessingContext pc, RenderingContext rc, IChunkFactory 
  cacheDataChunkFactory, IChunkFactory yukonCompiledDefinition, Boolean& dataCached)
  at Microsoft.Reporting.LocalService.CreateSnapshotAndRender(CatalogItemContextBase itemContext, 
  ReportProcessing repProc, IRenderingExtension renderer, ProcessingContext pc, RenderingContext rc, 
  SubreportCallbackHandler subreportHandler, ParameterInfoCollection parameters, 
  DatasourceCredentialsCollection credentials)
  at Microsoft.Reporting.LocalService.Render(CatalogItemContextBase itemContext, Boolean 
  allowInternalRenderers, ParameterInfoCollection reportParameters, IEnumerable dataSources, 
  DatasourceCredentialsCollection credentials, CreateAndRegisterStream createStreamCallback, 
  ReportRuntimeSetup runtimeSetup)
  at Microsoft.Reporting.WebForms.LocalReport.InternalRender(String format, Boolean 
  allowInternalRenderers, String deviceInfo, PageCountMode pageCountMode, CreateAndRegisterStream 
  createStreamCallback, Warning[]& warnings)

我不明白 rdlc 和 Ninject 之间的关系。

我的报告生成方法->

        public static byte[] ReportByte(string dataSourceName, object dataSource, string reportFileName, FileLayout fileLayout = FileLayout.Potrait)
    {
        try
        {
            var lr = new LocalReport();

            var path = Path.Combine(HttpContext.Current.Server.MapPath("~/Reports/Rdlc"), reportFileName);
            if (!File.Exists(path))
                throw new ArgumentException("report not found");

            lr.ReportPath = path;

            var rd = new ReportDataSource(dataSourceName, dataSource);
            lr.DataSources.Add(rd);

            string reportType = "pdf";
            string mimeType;
            string encoding;
            string fileNameExtension;
            string deviceInfo = string.Empty;

            if (fileLayout == FileLayout.Landscape)
            {
                deviceInfo = "<DeviceInfo>" +
                "  <OutputFormat>pdf</OutputFormat>" +
                "  <PageWidth>11in</PageWidth>" +
                "  <PageHeight>8.5in</PageHeight>" +
                "  <MarginTop>0.5in</MarginTop>" +
                "  <MarginLeft>.50in</MarginLeft>" +
                "  <MarginRight>.50in</MarginRight>" +
                "  <MarginBottom>0.50in</MarginBottom>" +
                "</DeviceInfo>";
            }
            else
            {
                deviceInfo = "<DeviceInfo>" +
                "  <OutputFormat>pdf</OutputFormat>" +
                "  <PageWidth>8.5in</PageWidth>" +
                "  <PageHeight>11in</PageHeight>" +
                "  <MarginTop>0.5in</MarginTop>" +
                "  <MarginLeft>.50in</MarginLeft>" +
                "  <MarginRight>.50in</MarginRight>" +
                "  <MarginBottom>0.50in</MarginBottom>" +
                "</DeviceInfo>";
            }

            Warning[] warnings;
            string[] streams;
            byte[] renderedBytes;

            renderedBytes = lr.Render(
                reportType,
                deviceInfo,
                out mimeType,
                out encoding,
                out fileNameExtension,
                out streams,
                out warnings);

            return renderedBytes;
        }
        catch (Exception)
        {
            throw;
        }
    }

我也在分享我的依赖内核创建方法->

     private static IKernel CreateKernel()
    {
        var kernel = new StandardKernel();
        try
        {
            kernel.Load(Assembly.GetExecutingAssembly());
            HttpConfiguration.DependencyResolver = kernel.Get<System.Web.Http.Dependencies.IDependencyResolver>();
            return kernel;
        }
        catch
        {
            kernel.Dispose();
            throw;
        }
    }

【问题讨论】:

    标签: asp.net-web-api ninject rdlc dynamic-rdlc-generation


    【解决方案1】:

    似乎Ninject.WebApi 3.3.1 存在序列化问题。我只是将其更改为3.3.0。现在一切对我来说都很好。希望这可以帮助其他将来面临这个问题的人。

    【讨论】:

      猜你喜欢
      • 2021-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-02
      相关资源
      最近更新 更多