System.Exception: Compilation error: Cannot implicitly convert type 'int' to 'System.DateTime'
System.Exception: Compilation error: Cannot implicitly convert type 'int' to 'System.DateTime'
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)
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)
-
- Posts: 5442
- Joined: Tue Mar 20, 2018 5:34 am
Re: System.Exception: Compilation error: Cannot implicitly convert type 'int' to 'System.DateTime'
Hello,
Error with type converting ('int' to 'System.DateTime'). Without a report, it is difficult exactly where that error occurs.
Thank you.
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'
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
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
-
- Posts: 5442
- Joined: Tue Mar 20, 2018 5:34 am
Re: System.Exception: Compilation error: Cannot implicitly convert type 'int' to 'System.DateTime'
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.
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'
Hello,
Can we pass value to the variable with date type and init By expression

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

Thanks
Last edited by vcs on Fri Apr 21, 2023 9:53 am, edited 3 times in total.
-
- Posts: 5442
- Joined: Tue Mar 20, 2018 5:34 am
Re: System.Exception: Compilation error: Cannot implicitly convert type 'int' to 'System.DateTime'
Hello,
Yes, it is possible. What issue do you have?
Thank you.
Yes, it is possible. What issue do you have?
Thank you.
Re: System.Exception: Compilation error: Cannot implicitly convert type 'int' to 'System.DateTime'
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'.
Thank you!!
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!!
-
- Posts: 5442
- Joined: Tue Mar 20, 2018 5:34 am
Re: System.Exception: Compilation error: Cannot implicitly convert type 'int' to 'System.DateTime'
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.
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'
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.
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'
As an alternative, you can still provide a value with DateSerial expression
dateDebutVar.InitBy = StiVariableInitBy.Expression;
dateDebutVar.Value = "DateSerial(2000,01,01)";
dateDebutVar.InitBy = StiVariableInitBy.Expression;
dateDebutVar.Value = "DateSerial(2000,01,01)";