System.Exception: Compilation error: Cannot implicitly convert type 'int' to 'System.DateTime'

Stimulsoft Ultimate discussion
otcm
Posts: 8
Joined: Tue Feb 11, 2020 6:48 am

System.Exception: Compilation error: Cannot implicitly convert type 'int' to 'System.DateTime'

Post by otcm »

Hello team,

I was trying to generate a report however I got an error " System.Exception: Compilation error: Cannot implicitly convert type 'int' to 'System.DateTime'" when trying to process a date value, below is the log from the application, could you please suggest what could be wrong?

2023-02-10 10:14:25,750|GenerateReportMiddleware|ERROR: Exception while generating the report.
System.Exception: Compilation error: Cannot implicitly convert type 'int' to 'System.DateTime'
Cannot implicitly convert type 'int' to 'System.DateTime'

at Stimulsoft.Report.StiReport.Compile(String path, Stream stream, StiOutputType outputType, Boolean autoCreate, Object standaloneReportType)
at Stimulsoft.Report.StiReport.Compile(String path, Stream stream, StiOutputType outputType, Boolean autoCreate)
at Stimulsoft.Report.StiReport.Compile(String path, StiOutputType outputType, Boolean autoCreate)
at Stimulsoft.Report.StiReport.Compile(String path, StiOutputType outputType)
at Stimulsoft.Report.StiReport.Compile(StiOutputType outputType)
at Stimulsoft.Report.StiReport.Compile()
at Stimulsoft.Report.Engine.StiReportV2Builder.RenderSingleReport(StiReport masterReport, StiRenderState renderState)
at Stimulsoft.Report.StiReport.RenderReport(StiRenderState renderState)
at Stimulsoft.Report.StiReport.Render(StiRenderState renderState, StiGuiMode guiMode)
at Stimulsoft.Report.StiReport.Render(StiRenderState renderState)
at Stimulsoft.Report.StiReport.Render(Boolean showProgress, Int32 fromPage, Int32 toPage)
at Stimulsoft.Report.StiReport.Render(Boolean showProgress)
Lech Kulikowski
Posts: 6196
Joined: Tue Mar 20, 2018 5:34 am

Re: System.Exception: Compilation error: Cannot implicitly convert type 'int' to 'System.DateTime'

Post by Lech Kulikowski »

Hello,

Error with type converting ('int' to 'System.DateTime'). Without a report, it is difficult exactly where that error occurs.

Thank you.
otcm
Posts: 8
Joined: Tue Feb 11, 2020 6:48 am

Re: System.Exception: Compilation error: Cannot implicitly convert type 'int' to 'System.DateTime'

Post by otcm »

Hi Lech,

Thanks for the reply, actually I'm using a code to call the report:

    objDS.DataSetName = "otcm-DataSource";
                        string rowCount = "0";
                        if ((objDS.Tables.Count > 0))
                        {
                            rowCount = objDS.Tables[0].Rows.Count.ToString();
                        }
                        _logger.LogInformation($"GenerateRep DatsetName: {objDS.DataSetName} (TableCount: {objDS.Tables.Count.ToString()}");
                        _logger.LogInformation($"Record Count:{rowCount} TableCount: {objDS.Tables.Count.ToString()}");
                        _logger.LogInformation(" Regdata Start ");
                        objRepDes.RegData(objDS);
                        _logger.LogInformation("Regdata End ");
                        objRepDes.Dictionary.Synchronize();
                        objRepDes.CacheAllData = true;
                        objRepDes.Render(false);
                        _logger.LogInformation("Render(False) complete");


The Dictionary.Synchronize() method is calling Stimulsoft dictionary to set the data:

public StiDictionary Dictionary { get; set; }         //
        // Summary:
        //     Gets data sources of the report.
        [Browsable(false)]
        [StiBrowsable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]

I would like to know what int variable will be convert to System.Datetime...

Thanks,
J
Lech Kulikowski
Posts: 6196
Joined: Tue Mar 20, 2018 5:34 am

Re: System.Exception: Compilation error: Cannot implicitly convert type 'int' to 'System.DateTime'

Post by Lech Kulikowski »

Hello,

It is difficult to say something about the issue by that code.
Please send us a sample that reproduces the issue for analysis.

Thank you.
vcs
Posts: 2
Joined: Thu Apr 20, 2023 4:56 am

Re: System.Exception: Compilation error: Cannot implicitly convert type 'int' to 'System.DateTime'

Post by vcs »

Hello,

Can we pass value to the variable with date type and init By expression

Image

Thanks
Last edited by vcs on Fri Apr 21, 2023 9:53 am, edited 3 times in total.
Lech Kulikowski
Posts: 6196
Joined: Tue Mar 20, 2018 5:34 am

Re: System.Exception: Compilation error: Cannot implicitly convert type 'int' to 'System.DateTime'

Post by Lech Kulikowski »

Hello,

Yes, it is possible. What issue do you have?

Thank you.
vcs
Posts: 2
Joined: Thu Apr 20, 2023 4:56 am

Re: System.Exception: Compilation error: Cannot implicitly convert type 'int' to 'System.DateTime'

Post by vcs »

We have variable 'mydate' that has data type as DateTime and that is init by expression set as Today.

It is working when we pass expression (Today). But it is failing (throwing below error at this point objRepDes.Render(false) while rendering report) when we pass the value like '2/3/2023'.

Code: Select all

System.Exception: Compilation error: Cannot implicitly convert type 'int' to 'System.DateTime'

   at Stimulsoft.Report.StiReport.Compile(String path, Stream stream, StiOutputType outputType, Boolean autoCreate, Object standaloneReportType)
   at Stimulsoft.Report.Engine.StiReportV2Builder.RenderSingleReport(StiReport masterReport, StiRenderState renderState)
   at Stimulsoft.Report.StiReport.RenderReport(StiRenderState renderState)
   at Stimulsoft.Report.StiReport.Render(StiRenderState renderState, StiGuiMode guiMode)
   at Stimulsoft.Report.StiReport.Render(Boolean showProgress)


Thank you!!
Lech Kulikowski
Posts: 6196
Joined: Tue Mar 20, 2018 5:34 am

Re: System.Exception: Compilation error: Cannot implicitly convert type 'int' to 'System.DateTime'

Post by Lech Kulikowski »

Hello,

How do you pass the '2/3/2023' value?
If you use the Expression, it should be the expression, not the value:
DataSerial(2023,3,2)
or
new DateTime(2023,3,2)

Thank you.
Geoffrey
Posts: 2
Joined: Mon Jan 02, 2023 5:36 pm

Re: System.Exception: Compilation error: Cannot implicitly convert type 'int' to 'System.DateTime'

Post by Geoffrey »

Had the same error trying to set a date value on some DateTime variable.

Worked fine with "Today" but not with actual dates values.
I tried several formats but format was not the issue.

Ended up setting "InitBy" property :
myVar.InitBy = StiVariableInitBy.Value;

...and now my report compiles with date value on myVar !

Note : I used "ValueObject" property instead of "Value", that way i can use an actual DateTime object without wondering about formats.

Tips : If you save the report as MRT file, you can actually see the wrong generated code.
It's hard to understand compile error without the code.
Geoffrey
Posts: 2
Joined: Mon Jan 02, 2023 5:36 pm

Re: System.Exception: Compilation error: Cannot implicitly convert type 'int' to 'System.DateTime'

Post by Geoffrey »

As an alternative, you can still provide a value with DateSerial expression

dateDebutVar.InitBy = StiVariableInitBy.Expression;
dateDebutVar.Value = "DateSerial(2000,01,01)";
Post Reply