Page 1 of 2

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

Posted: Wed Mar 08, 2023 11:32 am
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)

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

Posted: Wed Mar 08, 2023 10:14 pm
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.

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

Posted: Thu Mar 09, 2023 10:15 am
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

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

Posted: Thu Mar 09, 2023 10:02 pm
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.

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

Posted: Fri Apr 21, 2023 9:44 am
by vcs
Hello,

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

Image

Thanks

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

Posted: Fri Apr 21, 2023 10:17 am
by Lech Kulikowski
Hello,

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

Thank you.

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

Posted: Fri Apr 21, 2023 10:39 am
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!!

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

Posted: Tue Apr 25, 2023 12:23 pm
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.

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

Posted: Wed May 24, 2023 4:19 pm
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.

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

Posted: Thu May 25, 2023 4:50 pm
by Geoffrey
As an alternative, you can still provide a value with DateSerial expression

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