8000 Added new kb article nullreferenceexception-licensing-watermark-winfo… · telerik/reporting-docs@d5d4b50 · GitHub
[go: up one dir, main page]

Skip to content

Commit d5d4b50

Browse files
github-actions[bot]KB BotDimitarNikolovv06
authored
Added new kb article nullreferenceexception-licensing-watermark-winforms-reportviewer (#1721)
* Added new kb article nullreferenceexception-licensing-watermark-winforms-reportviewer * Update nullreferenceexception-licensing-watermark-winforms-reportviewer.md --------- Co-authored-by: KB Bot <kb-bot@telerik.com> Co-authored-by: Dimitar Nikolov <dnikolov@progress.com>
1 parent be02316 commit d5d4b50

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
title: NullReferenceException Thrown When Showing Report in WinForms Report Viewer
3+
description: "Learn how to resolve the NullReferenceException in Telerik Reporting when using the WinForms Report Viewer with no parent form."
4+
type: troubleshooting
5+
page_title: The WinForms Report Viewer Crashes When Not Inside a Parent Control
6+
meta_title: NullReferenceException in Telerik Reporting WinForms Report Viewer
7+
slug: nullreferenceexception-licensing-watermark-winforms-reportviewer
8+
tags: telerik reporting, winforms, licensing issue, nullreferenceexception, reportviewer
9+
res_type: kb
10+
ticketid: 1691214
11+
---
12+
13+
## Environment
14+
15+
<table>
16+
<tbody>
17+
<tr>
18+
<td>Product</td>
19+
<td>Progress® Telerik® Reporting</td>
20+
</tr>
21+
<tr>
22+
<td>Version</td>
23+
<td>19.1.25.521</td>
24+
</tr>
25+
</tbody>
26+
</table>
27+
28+
## Description
29+
30+
I encounter a `NullReferenceException` when attempting to display a report using the [WinForms Report Viewer]({%slug telerikreporting/using-reports-in-applications/display-reports-in-applications/windows-forms-application/overview%}). My NET WinForms application utilizes the embedded report engine and includes the proper `Telerik.Licensing` and WinForms Report Viewer NuGet packages.
31+
32+
While the build confirms a valid Telerik Reporting license, running the form crashes at `UILicenseProvider.cs` in the `ShowWatermark` method due to `base.LicenseInfo` being null.
33+
34+
## Error Message
35+
36+
```
37+
Telerik.ReportViewer.WinForms.Licensing.UiLicensePresenter.ShowWatermark(Action showWatermarkCallback)
38+
at Telerik.ReportViewer.Common.TelerikLicensePresenterBase.PresentWatermark(Action showWatermarkCallback)
39+
at Telerik.ReportViewer.WinForms.WinViewer.OnPaint(PaintEventArgs eventArgs)
40+
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
41+
at System.Windows.Forms.Control.WmPaint(Message& m)
42+
at System.Windows.Forms.Control.WndProc(Message& m)
43+
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
44+
at System.Windows.Forms.NativeWindow.Callback(HWND hWnd, MessageId msg, WPARAM wparam, LPARAM lpa
45+
```
46+
47+
## Cause
48+
49+
The issue occurs when the [RefreshReport()](/api/telerik.reportviewer.winforms.reportviewerbase#Telerik_ReportViewer_WinForms_ReportViewerBase_RefreshReport) method is called before the WinForms Report Viewer is added to a parent form/control. This behavior results in the licensing logic failing.
50+
51+
The issue arises because the WinForms Report Viewer requires a parent form in order to properly execute its licensing logic. Without a parent form, the `base.LicenseInfo` property is `null`, causing the `NullReferenceException` to be thrown.
52+
53+
## Solution
54+
55+
To resolve the issue, ensure that the WinForms Report Viewer control is added to a parent form before it starts rendering the report. For example, the reference to the WinForms Report Viewer can be added to the `Controls` collection of the parent form before invoking the [RefreshReport()](/api/telerik.reportviewer.winforms.reportviewerbase#Telerik_ReportViewer_WinForms_ReportViewerBase_RefreshReport) method:
56+
57+
````C#
58+
private void Form1_Load(object sender, EventArgs e)
59+
{
60+
var reportSource1 = new UriReportSource();
61+
reportSource1.Uri = "Barcodes Report.trdp";
62+
var reportViewer = new Telerik.ReportViewer.WinForms.ReportViewer();
63+
reportViewer.ReportSource = reportSource1;
64+
reportViewer.Dock = System.Windows.Forms.DockStyle.Fill;
65+
reportViewer.Name = "reportViewer1";
66+
reportViewer.TabIndex = 1;
67+
reportViewer.Visible = true;
68+
reportViewer.Size = new System.Drawing.Size(800, 600);
69+
70+
// add report viewer reference to the collection before the RefreshReport() method is invoked and the rendering begins
71+
this.Controls.Add(reportViewer);
72+
73+
reportViewer.RefreshReport();
74+
}
75+
````
76+
77+
78+
## See Also
79+
80+
* [WinForms Report Viewer]({%slug telerikreporting/using-reports-in-applications/display-reports-in-applications/windows-forms-application/overview%})
81+
* [RefreshReport() Method](/api/telerik.reportviewer.winforms.reportviewerbase#Telerik_ReportViewer_WinForms_ReportViewerBase_RefreshReport)
82+
* [Controls Collection in WinForms](https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.control.controls?view=windowsdesktop-9.0)
83+
* [Bug Report: NullReferenceException Thrown by WinForms Report Viewer](https://feedback.telerik.com/reporting/1691310-nullreferenceexception-thrown-by-the-winforms-report-viewer-when-there-is-no-parent-form)

0 commit comments

Comments
 (0)
0