Rdlc report unable to parse regular expression

413 Views Asked by At

I am using the .net framework 4.7.2. And In a web API project with Ninject dependency injection, I am trying to generate an rdlc report with an expression. The problem is the report is generating perfectly when I am not using any expression but everything goes wrong when using an expression. Just a normal sum expression of two fields of a dataset.

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

The two fields are dataset field(decimal)

Whenever I am trying to generate a report I am getting an error, below ->

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.

the stack trace ->

   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)

I am not understanding whats the relation between the rdlc and Ninject.

My report generation method ->

        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;
        }
    }

I am also sharing my dependency kernel creation method ->

     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;
        }
    }

My Ninject packages and report viewer packages

1

There are 1 best solutions below

0
On

Seems like Ninject.WebApi 3.3.1 has a serialization issue. I just changed it to 3.3.0. Now everything just works fine for me. Hope this helps other folks who will face the issue in the future.