Question AR6 report with watermark: Object reference not set to an instance of an object

rva1945

Member
Joined
Jun 28, 2010
Messages
12
Programming Experience
Beginner
We have a report designer in our .NET web app, and if the report has a watermark, I got this when trying to run it:


Línea 352: rea = New System.Xml.XmlTextReader(s)
Línea 353: r.DataSource = dt
Línea 354: r.LoadLayout(rea)
Línea 355: AgregaParametros(r)
Línea 356: r.Run()

Line 354 fires the error

I printed dt,s,r and rea values in the immediate command window, with or without the watermark (debugging with a breakpoint in line 354), they seem to be all the same, so no clue about what's hapenning here:

NO WATERMARK *******************************************************

?rea
"None"
System.Xml.XmlTextReader: "None"
AttributeCount: 0
BaseURI: ""
CanReadBinaryContent: True
CanReadValueChunk: False
CanResolveEntity: True
Depth: 0
EOF: False
HasAttributes: False
HasValue: False
IsDefault: False
IsEmptyElement: False
Item: In order to evaluate an indexed property, the property must be qualified and the arguments must be explicitly supplied by the user.
LocalName: ""
Name: ""
NamespaceURI: ""
NameTable: {System.Xml.NameTable}
NodeType: None {0}
Prefix: ""
QuoteChar: """"c
ReadState: Initial {0}
SchemaInfo: Nothing
Settings: Nothing
Value: ""
ValueType: {Name = "String" FullName = "System.String"}
XmlLang: ""
XmlSpace: None {0}

WATERMARK *******************************************************

?rea
"None"
System.Xml.XmlTextReader: "None"
AttributeCount: 0
BaseURI: ""
CanReadBinaryContent: True
CanReadValueChunk: False
CanResolveEntity: True
Depth: 0
EOF: False
HasAttributes: False
HasValue: False
IsDefault: False
IsEmptyElement: False
Item: In order to evaluate an indexed property, the property must be qualified and the arguments must be explicitly supplied by the user.
LocalName: ""
Name: ""
NamespaceURI: ""
NameTable: {System.Xml.NameTable}
NodeType: None {0}
Prefix: ""
QuoteChar: """"c
ReadState: Initial {0}
SchemaInfo: Nothing
Settings: Nothing
Value: ""
ValueType: {Name = "String" FullName = "System.String"}
XmlLang: ""
XmlSpace: None {0}


NO WATERMARK ********************************************************

?r
{DataDynamics.ActiveReports.ActiveReport}
CalculatedFields: {DataDynamics.ActiveReports.FieldCollection}
Components: {System.ComponentModel.Container}
Culture: Nothing
CurrentMasterReportQueue: Nothing
CurrentPage: Nothing
DataMember: Nothing
DataSource: {System.Data.DataTable}
Document: {DataDynamics.ActiveReports.Document.Document}
EnableScriptDebugging: False
ExpressionErrorMessage: Nothing
Fields: {DataDynamics.ActiveReports.FieldCollection}
Initializing: False
IsDirty: True
IsSerializing: False
LayoutAction: 7
MasterReport: False
MaxPages: 0
Name: Nothing
PageNumber: 1
PageSettings: {DataDynamics.ActiveReports.PageSettings}
Parameters: {DataDynamics.ActiveReports.ParameterCollection}
ParentReport: Nothing
PrintWidth: 6.5
Script: ""
ScriptLanguage: "C#"
ScriptReferences: {#mb.#sNn}
Sections: {DataDynamics.ActiveReports.SectionCollection}
ShowParameterUI: True
State: Idle {0}
StyleSheet: {DataDynamics.ActiveReports.StyleSheet}
UserData: Nothing
Version: "6.0.2250.0"
Watermark: Nothing
WatermarkAlignment: Center {2}
WatermarkPrintOnPages: Nothing
WatermarkSizeMode: Clip {0}

WATERMARK ***************************************************************

?r
{DataDynamics.ActiveReports.ActiveReport}
CalculatedFields: {DataDynamics.ActiveReports.FieldCollection}
Components: {System.ComponentModel.Container}
Culture: Nothing
CurrentMasterReportQueue: Nothing
CurrentPage: Nothing
DataMember: Nothing
DataSource: {System.Data.DataTable}
Document: {DataDynamics.ActiveReports.Document.Document}
EnableScriptDebugging: False
ExpressionErrorMessage: Nothing
Fields: {DataDynamics.ActiveReports.FieldCollection}
Initializing: False
IsDirty: True
IsSerializing: False
LayoutAction: 7
MasterReport: False
MaxPages: 0
Name: Nothing
PageNumber: 1
PageSettings: {DataDynamics.ActiveReports.PageSettings}
Parameters: {DataDynamics.ActiveReports.ParameterCollection}
ParentReport: Nothing
PrintWidth: 6.5
Script: ""
ScriptLanguage: "C#"
ScriptReferences: {#mb.#sNn}
Sections: {DataDynamics.ActiveReports.SectionCollection}
ShowParameterUI: True
State: Idle {0}
StyleSheet: {DataDynamics.ActiveReports.StyleSheet}
UserData: Nothing
Version: "6.0.2250.0"
Watermark: Nothing
WatermarkAlignment: Center {2}
WatermarkPrintOnPages: Nothing
WatermarkSizeMode: Clip {0}


N0 WATERMARK ************************************************************

?dt
{System.Data.DataTable}
CaseSensitive: False
ChildRelations: {System.Data.DataRelationCollection.DataTableRelationCollection}
Columns: {System.Data.DataColumnCollection}
Constraints: {System.Data.ConstraintCollection}
Container: Nothing
DataSet: {System.Data.DataSet}
DefaultView: {System.Data.DataView}
DesignMode: False
DisplayExpression: ""
ExtendedProperties: Count = 0
HasErrors: False
IsInitialized: True
Locale: {System.Globalization.CultureInfo}
MinimumCapacity: 50
Namespace: ""
ParentRelations: {System.Data.DataRelationCollection.DataTableRelationCollection}
Prefix: ""
PrimaryKey: {Length=0}
RemotingFormat: Xml {0}
Rows: {System.Data.DataRowCollection}
Site: Nothing
TableName: "Table"


WATERMARK ****************************************************

?dt
{System.Data.DataTable}
CaseSensitive: False
ChildRelations: {System.Data.DataRelationCollection.DataTableRelationCollection}
Columns: {System.Data.DataColumnCollection}
Constraints: {System.Data.ConstraintCollection}
Container: Nothing
DataSet: {System.Data.DataSet}
DefaultView: {System.Data.DataView}
DesignMode: False
DisplayExpression: ""
ExtendedProperties: Count = 0
HasErrors: False
IsInitialized: True
Locale: {System.Globalization.CultureInfo}
MinimumCapacity: 50
Namespace: ""
ParentRelations: {System.Data.DataRelationCollection.DataTableRelationCollection}
Prefix: ""
PrimaryKey: {Length=0}
RemotingFormat: Xml {0}
Rows: {System.Data.DataRowCollection}
Site: Nothing
TableName: "Table"

NO WATERMARK ************************************************************

?s
{System.IO.MemoryStream}
System.IO.MemoryStream: {System.IO.MemoryStream}
CanRead: True
CanSeek: True
CanTimeout: False
CanWrite: True
Length: 1551
Null: {System.IO.Stream.NullStream}
Position: 1551
ReadTimeout: {"Los tiempos de espera no se admiten en esta secuencia."}
WriteTimeout: {"Los tiempos de espera no se admiten en esta secuencia."}

NO WATERMARK ************************************************************

?s
{System.IO.MemoryStream}
System.IO.MemoryStream: {System.IO.MemoryStream}
CanRead: True
CanSeek: True
CanTimeout: False
CanWrite: True
Length: 310846
Null: {System.IO.Stream.NullStream}
Position: 8192
ReadTimeout: {"Los tiempos de espera no se admiten en esta secuencia."}
WriteTimeout: {"Los tiempos de espera no se admiten en esta secuencia."}
 
My best guess based on the information provided is that the Stream variable "s" is not at the beginning. It would be helpful if we can see the code before line 352. To ensure it is at teh begining just make sure that you use s.Position=0 before passing the stream to the XmlTextReader.

If that does not solve your problem, I encourage you to post the question in our support forums for ActiveReports. Many people may be able to help you there: ActiveReports 6 Support - GrapeCity

Scott Willeke
GrapeCity inc.
Also, if possible attach the actual .rpx file containing the watermark image. This way we can debug it.
 
S is a System.IO.Stream

reporte es a varbinary field and the report definition is stored there

s = New System.IO.MemoryStream(reporte)
rea = New System.Xml.XmlTextReader(s)
r.DataSource = dt
r.LoadLayout(rea)

(please remember all of this happens if the report includes a watermark)

Even setting s.position = 0 (it equals to 4096 before the error line) doesn't work, and it fires a different error which, translated literally from Spanish, is something like this: "Unexpected end of file. The following elements are not closed: Watermark3, ActiveReportsLayout. Líne 1, position 16467"
 
Based on the error message it is almost certain that the stream was not in the right position when the XmlTextReader was passed the stream. Either that, or the stream does not contain the whole .RPX file. Again, we need to see all the code before the lines you're showing. The limited lines you're showing are not enough. Also having the actual .rpx would be useful. Can you post a very simple project that can reproduce the problem? Then we can troubleshoot it.

Also, to reset the stream position, make sure that you're resetting it before it is passed to the XmlTextReader. And if the .rpx is coming from a file there is a .LoadLayout method overload that accepts a file path. Just pass the filename there and ActiveReports will load it directly. More information is at Saving and Loading RPX Files
 
The report WITHOUT WaterMark, in XML:

- <ActiveReportsLayout Version="3.1" PrintWidth="9360" DocumentName="ARNet Document" ScriptLang="C#" MasterReport="0">
- <StyleSheet>
<Style Name="Normal" Value="font-family: Arial; font-style: normal; text-decoration: none; font-weight: normal; font-size: 10pt; color: Black" />
<Style Name="Heading1" Value="font-size: 16pt; font-weight: bold" />
<Style Name="Heading2" Value="font-family: Times New Roman; font-size: 14pt; font-weight: bold; font-style: italic" />
<Style Name="Heading3" Value="font-size: 13pt; font-weight: bold" />
</StyleSheet>
- <Sections>
- <Section Type="PageHeader" Name="PageHeader1" Height="360" BackColor="16777215">
<Control Type="AR.Label" Name="Label1" Left="0" Top="0" Width="1440" Height="288" Caption="Codigo Empleado" Style="white-space: nowrap" />
</Section>
- <Section Type="Detail" Name="Detail1" Height="330" BackColor="16777215">
<Control Type="AR.Field" Name="TextBox1" DataField="REMPLES_Codigo" Tag="REMPLES | |Codigo | |" Left="0" Top="0" Width="1440" Height="288" Text="Codigo Empleado" Style="white-space: nowrap" />
</Section>
<Section Type="PageFooter" Name="PageFooter1" Height="360" BackColor="16777215" />
</Sections>
<ReportComponentTray />
<PageSettings LeftMargin="567" RightMargin="567" TopMargin="567" BottomMargin="567" />
- <Parameters>
<Parameter Key="Parameter1" DefaultValue="" PromptUser="1" />
<Parameter Key="Parameter2" DefaultValue="" PromptUser="1" />
<Parameter Key="Parameter3" DefaultValue="" PromptUser="1" />
<Parameter Key="Parameter4" DefaultValue="" PromptUser="1" />
<Parameter Key="Parameter5" DefaultValue="" PromptUser="1" />
</Parameters>
</ActiveReportsLayout>

Now the report WITH the WaterMark (a small jpg):

- <ActiveReportsLayout Version="3.1" PrintWidth="9360" DocumentName="ARNet Document" ScriptLang="C#" MasterReport="0">
- <StyleSheet>
<Style Name="Normal" Value="font-family: Arial; font-style: normal; text-decoration: none; font-weight: normal; font-size: 10pt; color: Black" />
<Style Name="Heading1" Value="font-size: 16pt; font-weight: bold" />
<Style Name="Heading2" Value="font-family: Times New Roman; font-size: 14pt; font-weight: bold; font-style: italic" />
<Style Name="Heading3" Value="font-size: 13pt; font-weight: bold" />
</StyleSheet>
- <Sections>
- <Section Type="PageHeader" Name="PageHeader1" Height="360" BackColor="16777215">
<Control Type="AR.Label" Name="Label1" Left="0" Top="0" Width="1440" Height="288" Caption="Codigo Empleado" Style="white-space: nowrap" />
</Section>
- <Section Type="Detail" Name="Detail1" Height="330" BackColor="16777215">
<Control Type="AR.Field" Name="TextBox1" DataField="REMPLES_Codigo" Tag="REMPLES | |Codigo | |" Left="0" Top="0" Width="1440" Height="288" Text="Codigo Empleado" Style="white-space: nowrap" />
</Section>
<Section Type="PageFooter" Name="PageFooter1" Height="360" BackColor="16777215" />
</Sections>
<ReportComponentTray />
<PageSettings LeftMargin="567" RightMargin="567" TopMargin="567" BottomMargin="567" />
<Watermark3 WatermarkAlignment="2" SizeMode="0" WatermarkPrintOnPages="">$CDATA$0D0D000400D5030000FFD8FFE000104A46494600010101006000600000FFDB004300080606070605080707070909080A0C140D0C0B0B0C1912130F141D1A1F1E1D1A1C1C20242E2720222C231C1C2837292C30313434341F27393D38323C2E333432FFDB0043010909090C0B0C180D0D1832211C213232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232FFC0001108007400A403012200021101031101FFC4001F0000010501010101010100000000000000000102030405060708090A0BFFC400B5100002010303020403050504040000017D01020300041105122131410613516107227114328191A1082342B1C11552D1F02433627282090A161718191A25262728292A3435363738393A434445464748494A535455565758595A636465666768696A737475767778797A838485868788898A92939495969798999AA2A3A4A5A6A7A8A9AAB2B3B4B5B6B7B8B9BAC2C3C4C5C6C7C8C9CAD2D3D4D5D6D7D8D9DAE1E2E3E4E5E6E7E8E9EAF1F2F3F4F5F6F7F8F9FAFFC4001F0100030101010101010101010000000000000102030405060708090A0BFFC400B51100020102040403040705040400010277000102031104052131061241510761711322328108144291A1B1C109233352F0156272D10A162434E125F11718191A262728292A35363738393A434445464748494A535455565758595A636465666768696A737475767778797A82838485868788898A92939495969798999AA2A3A4A5A6A7A8A9AAB2B3B4B5B6B7B8B9BAC2C3C4C5C6C7C8C9CAD2D3D4D5D6D7D8D9DAE2E3E4E5E6E7E8E9EAF2F3F4F5F6F7F8F9FAFFDA000C03010002110311003F00E928A28AF34FC5C28A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A00FFFD9$FINCDATA$</Watermark3>
- <Parameters>
<Parameter Key="Parameter1" DefaultValue="" PromptUser="1" />
<Parameter Key="Parameter2" DefaultValue="" PromptUser="1" />
<Parameter Key="Parameter3" DefaultValue="" PromptUser="1" />
<Parameter Key="Parameter4" DefaultValue="" PromptUser="1" />
<Parameter Key="Parameter5" DefaultValue="" PromptUser="1" />
</Parameters>
</ActiveReportsLayout>
 
The rpx you've sent to me is not woring probably because it was corrupted when copy & pasted into this message as I couldn't get it to work (an attachment would have been better).

Anyway, I created a sample from scratch and it worked fine to use an rpx with a watermark. I have attached the full working example project.

The relevant working code from my sample is below:

VB.NET:
Private Sub btnLoadReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoadReport.Click
	Dim rpxPath As String = System.IO.Path.Combine(Application.StartupPath, "ActiveReportWithWatermark.rpx")
	Dim strm As System.IO.Stream = System.IO.File.OpenRead(rpxPath)
	Dim myXmlReader As System.Xml.XmlTextReader = New System.Xml.XmlTextReader(strm)
	Dim rpt As New DataDynamics.ActiveReports.ActiveReport

	rpt.LoadLayout(myXmlReader)

	Me.Viewer1.Document = rpt.Document
	rpt.Run()
End Sub

In the future it will be great if you can post your questions or problems with ActiveReports in the ActiveReports technical support forum at our website at the following location: ActiveReports 6 Support - GrapeCity

Thank you for using ActiveReports!

Scott Willeke
GrapeCity inc.
 

Attachments

  • ARLoadRpx.zip
    47.2 KB · Views: 25
Well, we store the rpx contents n a varbinary field in a table, that's the reason why

s = New System.IO.MemoryStream(reporte)
rea = New System.Xml.XmlTextReader(s)
r.DataSource = dt
r.LoadLayout(rea)

And I remind you that it works without a watermark.
 
I understand that you might be loading the stream from a database rather than the file as was done in my sample. However, obviously the content of the stream is the same whether it comes from a file for a varbinary field in a database. So as long as you get exactly the same bits from the varbinary field as what ActiveReports saves, it will work fine and the rest of the code dealing with the stream will be the same.

If it is not working in your environment still, we are left to conclude only that the stream/rpx data was corrupted when saving or retrieving from the varbinary field in the database.
 
Back
Top