none
Handle with Reporting Services exceptions to output custom message - error The type 'ReportErrorEventArgs' exists in both 'Microsoft.ReportViewer.WebForms' and 'ReportingServicesWebServer'

    Pertanyaan

  • My first purpose to handle with Microsoft Reporting Service error and output custom message with help of ReportErrorEventHandler. See more on msdn about ReportErrorEventHandler.
    To test it I have created ASP.net Empty Web Site in Visual Studio 2017 (.NET Framework 4.6.1). Added masterpage ReportViewer.aspx, code behind page ReportViewer.aspx.cs, config file Web.Config. Registered two assemblies ReportingServicesWebServer and Microsoft.ReportViewer.WebForms

    <%@ Register assembly="ReportingServicesWebServer, Version=13.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" Namespace="Microsoft.ReportingServices.WebServer"  TagPrefix="RS"%>
    <%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>

    because default Microsoft Reporting Services page contains RS:ReportViewerHost user control which requires ReportingServicesWebServer assembly, and ReportErrorEventHandler requires Microsoft.ReportViewer.WebForms according to msdn article mentioned above.

    As a result a get an error

    The type 'ReportErrorEventArgs' exists in both 'Microsoft.ReportViewer.WebForms, Version=14.0.0.0, Culture=neutral, 
    PublicKeyToken=89845dcd8080cc91' and 'ReportingServicesWebServer, Version=13.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91'    
    ReportViewer.aspx.cs  

    When I'm trying to use namespace Microsoft.ReportingServices.WebServer instead of Microsoft.Reporting.WebForms, it tells me

    The type or namespace name 'ReportErrorEventArgs' could not be found (are you missing a using directive or an assembly reference?) ReportViewer.aspx.cs

    Also I didn't find how to use alias for references to use specific assembly, because there is noreference section in my solution explorer.

    How could I hold both assemblies and get rid of an error. Thanks in advance!

    ReportViewer.aspx.cs code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace Microsoft.Reporting.WebForms
    {
        public partial class ReportViewer1 : System.Web.UI.Page
        {
            public void ReportErrorEventHandler(object sender, ReportErrorEventArgs e)
            {
                Exception ex = e.Exception;
                ReportErrorMessage.Text = ex.Message;
                while (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                    ReportErrorMessage.Text = ReportErrorMessage.Text + ex.Message;
                }
                ReportErrorMessage.Visible = true;
                if (ReportErrorMessage.Text.Contains("rsErrorOpeningConnection"))
                {
                    ReportErrorMessage.Text = "The database is under everyday maintanence now. Please try again in 20 minutes.";
                }
                e.Handled = true;
            }
        }
    }

    ReportViewer.aspx code:

    <%@ Register assembly="ReportingServicesWebServer, Version=13.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" Namespace="Microsoft.ReportingServices.WebServer"  TagPrefix="RS"%>
    <%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="ReportViewer.aspx.cs" Inherits="Microsoft.Reporting.WebForms.ReportViewer1" EnableEventValidation="false" %>
    
    <!DOCTYPE html>
    
    <script runat="server">
    
    </script>
    <html>
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
        <form id="ReportViewerForm" runat="server">
          <asp:scriptmanager runat="server"></asp:scriptmanager>
             <asp:label runat="server" id="ReportErrorMessage" Visible="false"></asp:label>
             <table cellspacing="0" cellpadding="0" width="100%" height="100%"><tr height="100%"><td width="100%">
                <rsweb:ReportViewer ID="ReportViewerControl" runat="server" ProcessingMode="Remote" Height="100%" Width="100%" OnReportError="ReportErrorEventHandler">
                  <ServerReport ReportPath="<ReportPath>" ReportServerUrl="<URL>" />
                </rsweb:ReportViewer>
            </td></tr></table>
        </form>
    </body>
    </html>

    Note that ReportViewer.aspx does not contains RS:ReportViewerHost user control, but contains rsweb:ReportViewer, because it is test project. And if remove ReportingServicesWebServerassembly it will work as expected. But production web page requires both assemblies, ReportingServicesWebServer for RS:ReportViewerHost user control and Microsoft.ReportViewer.WebForms to use ReportErrorEventHandler.





    • Diedit oleh fapw 29 Agustus 2018 12:44 made title more concrete
    • Dipindahkan oleh CoolDadTxMVP 29 Agustus 2018 14:07 ASP.NET related
    29 Agustus 2018 12:35

Semua Balasan