lkosson / reportviewercore

Recompilation of Microsoft.ReportViewer for .NET Core 3.1+
414 stars 121 forks source link

Calling DataSources on Microsoft.Reporting.WinForms.LocalReport fails #38

Closed AlanMichaelDobson closed 3 years ago

AlanMichaelDobson commented 3 years ago

Hi

I am getting this error CustomCode(2) : error BC30456: 'RegularExpressions' is not a member of 'System.Text'. in code that ran successfully under .Net Framework but fails under .Net 5 If required I will happily narrow down in a test harness if the data below is not enough

Thank you Alan Dobson

Local property

public Microsoft.Reporting.WinForms.LocalReport Report { get; private set; }

Error Call

this.Report.GetDataSourceNames()

Failure method

public void SetDataSet(DataSet dataset) { this.DataSet = dataset;

foreach (string sDataSourceName in this.Report.GetDataSourceNames()) 
{
    if (dataset.Tables.Contains(sDataSourceName))
    {
        ReportDataSource oDataSource = this.Report.DataSources[sDataSourceName];

        if (oDataSource == null)
        {
            oDataSource = new ReportDataSource(sDataSourceName, dataset.Tables[sDataSourceName]);

            this.Report.DataSources.Add(oDataSource);
        }
        else
        {
            oDataSource.Value = dataset.Tables[sDataSourceName];
        }
    }
}

}

Exception details from the debugger

Microsoft.Reporting.WinForms.LocalProcessingException HResult=0x80131500 Message=An error occurred during local report processing. Source=Microsoft.ReportViewer.WinForms StackTrace: at Microsoft.Reporting.WinForms.LocalReport.EnsureExecutionSession() at Microsoft.Reporting.WinForms.LocalReport.GetDataSourceNames() at SDS.Optical.Windows.BPL.Reports.SDSLocalReport.SetDataSet(DataSet dataset) in E:\Release_60\ClassLibraries\SDS.Optical.Windows.BPL\Reports\SDSLocalReport.cs:line 195

This exception was originally thrown at this call stack: [External Code]

Inner Exception 1: DefinitionInvalidException: The definition of the report '' is invalid.

Inner Exception 2: ReportProcessingException: An unexpected error occurred in Report Processing.

Inner Exception 3: InvalidOperationException: CustomCode(2) : error BC30456: 'RegularExpressions' is not a member of 'System.Text'.

More comprehensive stack trace from our QA team

ExceptionType: System.InvalidOperationException TargetSite: System.CodeDom.Compiler.CompilerResults CompileAssemblyFromDom(System.CodeDom.Compiler.CompilerParameters, System.CodeDom.CodeCompileUnit[]) Message: CustomCode(2) : error BC30456: 'RegularExpressions' is not a member of 'System.Text'. Data: HelpLink: NULL Source: Microsoft.ReportViewer.Common HResult: -2146233079 StackTrace: at Microsoft.ReportingServices.RdlExpressions.VBExpressionCodeProvider.CompileAssemblyFromDom(CompilerParameters options, CodeCompileUnit[] compilationUnits) at Microsoft.ReportingServices.RdlExpressions.ExprHostCompiler.InternalCompile(AppDomain compilationTempAppDomain, Boolean refusePermissions) at Microsoft.ReportingServices.RdlExpressions.ExprHostCompiler.<>c__DisplayClass46_0.b__0() at Microsoft.ReportingServices.Diagnostics.RevertImpersonationContext.Run(ContextBody callback) at Microsoft.ReportingServices.RdlExpressions.ExprHostCompiler.Compile(IExpressionHostAssemblyHolder expressionHostAssemblyHolder, AppDomain compilationTempAppDomain, Boolean refusePermissions, PublishingVersioning versioning) at Microsoft.ReportingServices.ReportPublishing.ReportPublishing.Phase3(ParameterInfoCollection& parameters, Dictionary`2& groupingExprCountAtScope) at Microsoft.ReportingServices.ReportPublishing.ReportPublishing.InternalCreateIntermediateFormat(Stream definitionStream, String& description, String& language, ParameterInfoCollection& parameters, DataSourceInfoCollection& dataSources, DataSetInfoCollection& sharedDataSetReferences, UserLocationFlags& userReferenceLocation, ArrayList& dataSetsName, Boolean& hasExternalImages, Boolean& hasHyperlinks, Byte[]& dataSetsHash) at Microsoft.ReportingServices.ReportPublishing.ReportPublishing.CreateIntermediateFormat(Byte[] definition, String& description, String& language, ParameterInfoCollection& parameters, DataSourceInfoCollection& dataSources, DataSetInfoCollection& sharedDataSetReferences, UserLocationFlags& userReferenceLocation, ArrayList& dataSetsName, Boolean& hasExternalImages, Boolean& hasHyperlinks, Byte[]& dataSetsHash) at Microsoft.ReportingServices.ReportProcessing.ReportProcessing.CompileOdpReport(PublishingContext reportPublishingContext, PublishingErrorContext errorContext, String& reportDescription, String& reportLanguage, ParameterInfoCollection& parameters, DataSourceInfoCollection& dataSources, DataSetInfoCollection& sharedDataSetReferences, UserLocationFlags& userReferenceLocation, ArrayList& dataSetsName, Boolean& hasExternalImages, Boolean& hasHyperlinks, Byte[]& dataSetsHash) at Microsoft.ReportingServices.ReportProcessing.ReportProcessing.CreateIntermediateFormat(PublishingContext reportPublishingContext)

lkosson commented 3 years ago

There seems to be an expression in your report that directly or indirectly uses regexes. Please inspect your RDLC for such expression and provide it here so I can replicate the issue locally. Most likely cause is missing assembly reference in VB compiler invocation. In .NET Framework System.Text.RegularExpressions used to live in System.dll, now it is in (unreferenced) System.Text.RegularExpressions.dll.

AlanMichaelDobson commented 3 years ago

Hi

Below is the only regex in the XML for the report

Public Function ConvertRtfToTextRegex(ByVal input As String) As String Dim returnValue As String = String.Empty returnValue = System.Text.RegularExpressions.Regex.Replace(input, "{*?\[^{}]+}|[{}]|\\n?[A-Za-z]+\n?(?:-?\d+)?[ ]?", "") Return returnValue End Function

Strange that it references System.Text.RegularExpressions

lkosson commented 3 years ago

I have added System.Text.RegularExpressions.dll assembly reference to Roslyn compiler input. Please check if this solves the issue.