Skip to content

"Invalid cast from 'System.String' to 'System.TimeSpan'." is thrown when getting value of output parameter which its type is TIME #680

Closed

Description

@nhathongly

I got this exception when trying get the output value of TIME

System.InvalidCastException : Invalid cast from 'System.String' to 'System.TimeSpan'.
 StackTrace:
   at System.Convert.DefaultToType(IConvertible value, Type targetType, IFormatProvider provider)
   at System.String.System.IConvertible.ToType(Type type, IFormatProvider provider)
   at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
   at System.Convert.ChangeType(Object value, Type conversionType)
   at MySqlConnector.Core.DbTypeMapping.DoConversion(Object obj) in C:\projects\mysqlconnector\src\MySqlConnector\Core\DbTypeMapping.cs:line 22
   at MySqlConnector.Core.StoredProcedureCommandExecutor.SetParams() in C:\projects\mysqlconnector\src\MySqlConnector\Core\StoredProcedureCommandExecutor.cs:line 108
   at MySql.Data.MySqlClient.MySqlCommand.ReaderClosed() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlCommand.cs:line 452
   at MySql.Data.MySqlClient.MySqlDataReader.DoClose() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlDataReader.cs:line 445
   at MySql.Data.MySqlClient.MySqlDataReader.Dispose(Boolean disposing) in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlDataReader.cs:line 282

Activity

  1. bgrainger commented on Aug 14, 2019

    @bgrainger
    Member

    It looks like you might be using a stored procedure with an OUT parameter. Can you provide more details on how to reproduce this, e.g., table definition, stored procedure definition, sample code?

  2. nhathongly commented on Aug 14, 2019

    @nhathongly
    Author

    My stored procedure is simply like this

    CREATE DEFINER=`root`@`%` PROCEDURE `GetTime`(OUT OutTime TIME)
    BEGIN
    	SET OutTime = CURTIME();
    END

    I'm totally new to MySql, so I don't know if I get any mistake. It worked perfectly with MySql.Data-8.0.16

  3. self-assigned this
    on Aug 14, 2019
  4. added 2 commits that reference this issue on Aug 14, 2019
    8317b1e
    2eaf1d1
  5. nhathongly commented on Aug 30, 2019

    @nhathongly
    Author

    Hi there,

    I experienced the same issue when the data type of OUTPUT parameter is BOOL. The exception said that "Object of type 'System.SByte' cannot be converted to type 'System.Boolean'." when I tried to map the OUTPUT to a bool variable.
    Could you have a check?

    Thanks

  6. nhathongly commented on Aug 30, 2019

    @nhathongly
    Author

    When I executed the following script, I saw that the DTD_IDENTIFIER value in information_schema.parameters of a BOOL parameter was TINYINT(1)

    SELECT ORDINAL_POSITION, PARAMETER_MODE, PARAMETER_NAME, DTD_IDENTIFIER
    FROM information_schema.parameters
    WHERE SPECIFIC_SCHEMA = 'DB Name' AND SPECIFIC_NAME = 'Routine Name'
    ORDER BY ORDINAL_POSITION;
    ORDINAL_POSITION PARAMETER_MODE PARAMETER_NAME DTD_IDENTIFIER
    1 IN js json
    2 OUT b tinyint(1)
  7. nhathongly commented on Aug 30, 2019

    @nhathongly
    Author

    Seem it will be fixed when 782a765 is released

    @bgrainger may I know when will we have the next release? Thank you in advance

  8. bgrainger commented on Aug 30, 2019

    @bgrainger
    Member

    I'll release 0.57.0-beta9 with this fix soon. The beta versions are tested and reliable enough to run in production; they just haven't shipped as a "stable" release yet due to breaking API changes in this series.

  9. bgrainger commented on Aug 30, 2019

    @bgrainger
    Member

    0.57.0-beta9 is available with this fix.

  10. added theissue type on Jan 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions