ReportViewer 15.0.0 渲染:Sys.ArgumentNullException:值不能为空。参数名称:元素

Posted

技术标签:

【中文标题】ReportViewer 15.0.0 渲染:Sys.ArgumentNullException:值不能为空。参数名称:元素【英文标题】:ReportViewer 15.0.0 Renerding: Sys.ArgumentNullException: Value cannot be null. Parameter name: element 【发布时间】:2019-11-07 18:48:45 【问题描述】:

我在使用 MS ReportViewer 呈现报告(带有特定参数集)时遇到以下问题。从内部 ReportViewer JS 代码调用的 JS 失败,特别是“ScriptResource.axd”的这一部分:

var $addHandlers = Sys.UI.DomEvent.addHandlers = function Sys$UI$DomEvent$addHandlers(element, events, handlerOwner, autoRemove) 
    /// <summary locid="M:J#Sys.UI.DomEvent.addHandlers" />
    /// <param name="element"></param>
    /// <param name="events" type="Object"></param>
    /// <param name="handlerOwner" optional="true"></param>
    /// <param name="autoRemove" type="Boolean" optional="true"></param>
    var e = Function._validateParams(arguments, [
        name: "element",
        name: "events", type: Object,
        name: "handlerOwner", optional: true,
        name: "autoRemove", type: Boolean, optional: true
    ]);
    if (e) throw e;
    Sys.UI.DomEvent._ensureDomNode(element);
    for (var name in events) 
        var handler = events[name];
        if (typeof(handler) !== 'function') throw Error.invalidOperation(Sys.Res.cantAddNonFunctionhandler);
        if (handlerOwner) 
            handler = Function.createDelegate(handlerOwner, handler);
        
        $addHandler(element, name, handler, autoRemove || false);
    

“Sys.UI.DomEvent._ensureDomNode(element);”行失败并出现以下错误:

Sys.ArgumentNullException:值不能为空。参数名称: 元素

当我查找堆栈跟踪时:

看来这个问题的根源是从主“报告”页面调用的JS:

Sys.Application.add_init(function() 
    $create(Microsoft.Reporting.WebFormsClient._Splitter, "HoverStyle":"SplitterHover","ImageCollapse":"/Reserved.ReportViewerWebControl.axd?OpType=Resource\u0026Version=15.0.900.148\u0026Name=Microsoft.Reporting.WebForms.Icons.SplitterHorizCollapse.png","ImageCollapseHover":"/Reserved.ReportViewerWebControl.axd?OpType=Resource\u0026Version=15.0.900.148\u0026Name=Microsoft.Reporting.WebForms.Icons.SplitterHorizCollapseHover.png","ImageExpand":"/Reserved.ReportViewerWebControl.axd?OpType=Resource\u0026Version=15.0.900.148\u0026Name=Microsoft.Reporting.WebForms.Icons.SplitterHorizExpand.png","ImageExpandHover":"/Reserved.ReportViewerWebControl.axd?OpType=Resource\u0026Version=15.0.900.148\u0026Name=Microsoft.Reporting.WebForms.Icons.SplitterHorizExpandHover.png","ImageId":"ctl00_ApplicationBody_rvReport_ToggleParam_img","IsCollapsable":true,"NormalStyle":"SplitterNormal","Resizable":false,"StoreCollapseField":"ctl00_ApplicationBody_rvReport_ToggleParam_collapse","StorePositionField":"ctl00_ApplicationBody_rvReport_ToggleParam_store","TooltipCollapse":"Hide Parameters","TooltipExpand":"Show Parameters","Vertical":false, null, null, $get("ctl00_ApplicationBody_rvReport_ToggleParam"));
);

这会破坏呈现的报告。我不确定如何进一步追踪这一点,我知道您可以使用不同的参数格式化报告,但我不明白如何调试 ReportViewer 库内部的缩小 JS。

此 JS 故障是否是某些报告的已知问题?我正在运行最新版本的库(15.0.0)。我会发布报告和参数,但是它们包含敏感信息。如何调试 ReportViewer 库内部的问题以解决此类问题?

【问题讨论】:

【参考方案1】:

非常棘手,我在 MasterPage 中运行了一个 C# 方法,它禁用了某些类型的控件,因此用户无法“编辑”页面,看起来像这样:

//CommonFunctions
public static List<T> GetAllControlsRecursiveByType<T>(ControlCollection Controls) where T : Control

    List<T> results = new List<T>();
    foreach (Control c in Controls)
    
        if (c is T)
        
            results.Add((T)c);
        

        if (c.HasControls())
        
            results.AddRange(GetAllControlsRecursiveByType<T>(c.Controls));
        
    
    return results;


public void DisableControls(Control control)

    if (control == null)
    
        return;
    

    DisableControl(control);
    foreach (System.Web.UI.Control c in control.Controls)
    
        DisableControl(c);

        // Recurse into child controls.
        if (c.Controls.Count > 0)
        
            DisableControls(c);
        
    


foreach (Control element in CommonFunctions.GetAllControlsRecursiveByType<Control>(FindControl("ApplicationBody").Controls))

    List<string> excludedIDs = new List<string>()  "btnAjaxDynamicFilterApplyFilter", "btnClose", "btnCancel", "btnExport" ;
    List<Type> includedTypes = new List<Type>()  typeof(LinkButton), typeof(Button), typeof(ImageButton), typeof(Repeater), typeof(ABC.Controls.ABCRepeater),
        typeof(GridView), typeof(ABC.Controls.ABCGridView), typeof(ABC.Controls.ImageCheckBox) ;

    if (!excludedIDs.Contains(element.ID) && includedTypes.Contains(element.GetType()))
    
        DisableControls(element);
    

原来这是在报表查看器中“禁用”某些呈现的控件,这反过来又破坏了前端的 JS。我通过从这个逻辑中排除“ReportViewer”来解决这个问题:

public bool ControlHasParentWithType(Control control, Type type)

    if (control == null || control.Parent == null)
    
        return false;
    
    else if (control.Parent.GetType() == type)
    
        return true;
    

    return ControlHasParentWithType(control.Parent, type);


//Within Method before disabling the control
if (ControlHasParentWithType(element, typeof(ReportViewer)))

    continue;

【讨论】:

以上是关于ReportViewer 15.0.0 渲染:Sys.ArgumentNullException:值不能为空。参数名称:元素的主要内容,如果未能解决你的问题,请参考以下文章

Linux指令:top

如何使用 g.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2) 缩放图像?

c#的reportViewer控件

ReportViewer技巧汇总

C#,reportviewer控件,怎么填充整个窗口

reportviewer需要的3个引用