TimeSpan and Nullable

Stimulsoft Reports.NET discussion
Tobias
Posts: 104
Joined: Mon Nov 24, 2008 8:44 am

TimeSpan and Nullable

Post by Tobias »

This is driving me nuts. I have a report with a datasource containing a TimeSpan.
At design-time the datasource contains some sample data and everything works just fine.

When printing this report with an empty datasource, I get an exception complaining about
System.Nullable not containing an Hours property.

http://pastie.org/2417798

(I'm setting StiOptions.Dictionary.UseNullableTimeSpan = false; !!!)

But if I call _stiReport.Design(); just before _stiReport.Render(); (without doing any modifications to the report) it works just fine.
Unfortunately I haven't been able to reproduce this outside of my application yet.

What's going wrong here? Where's the Nullable coming from?
Tobias
Posts: 104
Joined: Mon Nov 24, 2008 8:44 am

TimeSpan and Nullable

Post by Tobias »

Just figured out, that calling _stiReport.Dictionary.Synchronize(); before _stiReport.Render() makes this work.
Is it required to call this after RegData before rendering the report?
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

TimeSpan and Nullable

Post by HighAley »

Hello.
Tobias wrote:Just figured out, that calling _stiReport.Dictionary.Synchronize(); before _stiReport.Render() makes this work.
Is it required to call this after RegData before rendering the report?
We couldn't reproduce this bug.

Synchronize() is recommended to use before Render().

If you could send us sample project to reproduce the issue we'll try to find out a reason.

Thank you.
Tobias
Posts: 104
Joined: Mon Nov 24, 2008 8:44 am

TimeSpan and Nullable

Post by Tobias »

It's hard to create a sample project to reproduces this, because the data generated from POCO's is kinda complex.

Right now I must even do:

_stiReport.Dictionary.Synchronize();
_stiReport.Dictionary.Synchronize();

(two times - this is not a typo), otherwise I get an error in the designer because my TimeSpans are wrapped into Nullable.

Is there a way to export the data registered with a report in a way, that it can easily be loaded again?

Tobias
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

TimeSpan and Nullable

Post by HighAley »

Hello.
Tobias wrote:It's hard to create a sample project to reproduces this, because the data generated from POCO's is kinda complex.

Right now I must even do:

_stiReport.Dictionary.Synchronize();
_stiReport.Dictionary.Synchronize();

(two times - this is not a typo), otherwise I get an error in the designer because my TimeSpans are wrapped into Nullable.

Is there a way to export the data registered with a report in a way, that it can easily be loaded again?

Tobias
Unfortunately, we can't give you any advice, because we can't reproduce your issue. If you could send us a sample project, we'll try to find out the cause.

Thank you.
Tobias
Posts: 104
Joined: Mon Nov 24, 2008 8:44 am

Re: TimeSpan and Nullable

Post by Tobias »

Please see the code below and the attached sample. I've tested this with 2013.1.

1. If I call report.Dictionary.Synchronize() once, it works fine.
2. If I call report.Dictionary.Synchronize() twice, I will get an error in the designers preview, because the TimeSpan-Field now is Nullable<TimeSpan>
3. If I add a third call to report.Dictionary.Synchronize(), it works fine again.

The obvious workaround is to make sure, report.Dictionary.Synchronize() is called only once, but I think this should also work when called multiple times and the TimeSpan field should not suddenly become Nullable<>

Tobias

Code: Select all

var report = new StiReport();
report.Load("sample.mrt");

report.Dictionary.Variables.Clear();
foreach (var dataSource in report.DataSources)
{
    report.RegData(((StiDataSource)dataSource).Alias, new object[] { });
}

report.RegData("Data", new  List<Foo>
    {
        new Foo {Something = "Something 1", TimeSpan = TimeSpan.FromHours(1)},
        new Foo {Something = "Something 2", TimeSpan = TimeSpan.FromHours(2)},
        new Foo {Something = "Something 3", TimeSpan = TimeSpan.FromHours(3)},
        new Foo {Something = "Something 4", TimeSpan = TimeSpan.FromHours(4)},
        new Foo {Something = "Something 5", TimeSpan = TimeSpan.FromHours(5)},
    });
report.Dictionary.Synchronize();
report.Dictionary.Synchronize();
report.Design();
Attachments
sample.mrt
Sample report
(5.51 KiB) Downloaded 254 times
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: TimeSpan and Nullable

Post by Alex K. »

Hello,

Thank you for the sent code.
We need some additional time for check the issue.

Thank you.
Tobias
Posts: 104
Joined: Mon Nov 24, 2008 8:44 am

Re: TimeSpan and Nullable

Post by Tobias »

Any news on that?

It's even more weird. When doing Render() instead of Design() I MUST call Sychronize() TWICE, otherwise TimeSpans will get wrapped as Nullable and I get an exception.

So this throws:

Code: Select all

report.Dictionary.Synchronize();
report.Render();
But this doesn't:

Code: Select all

report.Dictionary.Synchronize();
report.Dictionary.Synchronize();
report.Render();
And this throws (On Preview):

Code: Select all

report.Dictionary.Synchronize();
report.Dictionary.Synchronize();
report.Design();
But this doesn't:

Code: Select all

report.Dictionary.Synchronize();
report.Design();
Tobias
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: TimeSpan and Nullable

Post by HighAley »

Hello.

We are still working on the issue.
We will let you know about the results.

Thank you.
Ivan
Posts: 960
Joined: Thu Aug 10, 2006 1:37 am

Re: TimeSpan and Nullable

Post by Ivan »

Hello,

The problem is solved.
The patch will be available in the next prerelease build.

Thank you.
Post Reply