Completed
Last Updated: 13 Dec 2019 15:20 by ADMIN
ADMIN
Ivan Hristov
Created on: 19 Nov 2019 15:16
Type: Bug Report
1
Cannot compile .NET Core 3 WinForms project that uses enumerations which exist in both System.Windows.Forms and Telerik.Reporting assemblies.

As virtually every product with 10+ years of development, Telerik Reporting has a certain amount of legacy code that was considered immutable at the time of writing. During the refactoring of our codebase to make it compatible with .NET Standard, we introduced a few types from System.Windows.Forms namespace to substitute the ones missing in the current version of the framework. Such types are System.Windows.Forms.CheckState and System.Windows.Forms.ControlPaint. Some of these types are introduced in recent release of .NET Core 3 for Windows Forms and therefore a conflict occurs between the types in our assemblies and the ones declared in .NET Core. The error is thrown in compile-time and it is similar to the one shown below:

The type 'CheckState' exists in both 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' and 'Telerik.Reporting, Version=13.2.19.918, Culture=neutral, PublicKeyToken=a9d7983dfcc261be'

 

In a future release of our product this collision will be avoided by using a dedicated enumeration for the duplicated types. A possible workaround would be to add an extern alias to the assembly reference of Telerik.Reporting. In this case all the references to Telerik.Reporting have to be edited to use the new alias, but the code that refers to the actual types from System.Windows.Forms will remain unchanged.

 

Here is how the Telerik.Reporting reference would look like in the application .csproj file:

  <ItemGroup>
    <Reference Include="Telerik.Reporting">
      <HintPath>..\..\..\Bin\netstandard2.0\Telerik.Reporting.dll</HintPath>
      <Aliases>telerikReporting</Aliases>
      </Reference>
  </ItemGroup>

 

Using the alias means that all the types in Telerik.Reporting namespace must be accessed with this alias. Unfortunately this also applies to C#/VB report definitions - their types must also be prepended with the alias, which could require significant effort. Here is a sample code file that initializes the WinForms Report Viewer and examines the CheckState of a CheckBox control in the form:

extern alias telerikReporting;

using System;
using System.Windows.Forms;

namespace WindowsFormsCoreDemo
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
            this.Load += this.Form1_Load;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.reportViewer.ReportSource = new telerikReporting::Telerik.Reporting.UriReportSource()
            {
                Uri = "SampleReport.trdp"
            };

            this.reportViewer.RefreshReport();
        }

        private void CheckBox_CheckedChanged(object sender, System.EventArgs e)
        {
            if (this.checkBox.CheckState == CheckState.Checked)
            {
                this.reportViewer.RefreshReport();
            }
        }
    }
}
0 comments