"String was not recognized as a valid DateTime." at login time

This is the place to report bugs and get support. When posting in this forum, please always provide as much detail as possible.

Please do not report problems with a custom build or custom code in this forum. If you are producing your own build from the source code and have problems or questions, ask in the developer forum, do not report it as a bug.

This is the place to report bugs and get support

When posting in this forum, please try to provide as many relevant details as possible. Particularly the following:

  • What operating system were you running when the bug appeared?
  • What database platform is your site using?
  • What version of mojoPortal are you running?
  • What version of .NET do you use?
  • What steps are necessary to reproduce the issue? Compare expected results vs actual results.
Please do not report problems with a custom build or custom code in this forum. If you are producing your own build from the source code and have problems or questions, ask in the developer forum.
This thread is closed to new posts. You must sign in to post in the forums.
8/14/2007 3:15:04 AM
Gravatar
Total Posts 22

"String was not recognized as a valid DateTime." at login time

I Joe,

I just installed MojoPortal 2.2.3.4 release for SQLite, but when I try to login with the admin account I get the following stack trace:

--

Server Error in '/MojoPortal' Application.
--------------------------------------------------------------------------------

String was not recognized as a valid DateTime.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.FormatException: String was not recognized as a valid DateTime.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[FormatException: String was not recognized as a valid DateTime.]
System.DateTimeParse.ParseExactMultiple(String s, String[] formats, DateTimeFormatInfo dtfi, DateTimeStyles style) +2239766
System.DateTime.ParseExact(String s, String[] formats, IFormatProvider provider, DateTimeStyles style) +46
Mono.Data.Sqlite.SqliteConvert.ToDateTime(String dateText) +138
Mono.Data.Sqlite.Sqlite3.GetDateTime(SqliteStatement stmt, Int32 index) +34
Mono.Data.Sqlite.Sqlite3.GetValue(SqliteStatement stmt, Int32 index, SqliteType& typ) +374
Mono.Data.Sqlite.SqliteDataReader.GetValue(Int32 i) +125
Mono.Data.Sqlite.SqliteDataReader.get_Item(String name) +24
mojoPortal.Business.SiteUser.GetUser(IDataReader reader) +1801
mojoPortal.Business.SiteUser.GetUser(String loginString) +94
mojoPortal.Business.SiteUser..ctor(SiteSettings settings, String login) +503
mojoPortal.Web.UI.SiteLogin.SiteLogin_LoggingIn(Object sender, LoginCancelEventArgs e) +46
System.Web.UI.WebControls.Login.OnLoggingIn(LoginCancelEventArgs e) +105
System.Web.UI.WebControls.Login.AttemptLogin() +67
System.Web.UI.WebControls.Login.OnBubbleEvent(Object source, EventArgs e) +99
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +115
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +163
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.832; ASP.NET Version:2.0.50727.832

--

I'm quite sure that the first attempt produced something a little different: the stack trace was the same except for these two lines:

mojoPortal.Web.UI.SiteLogin.SiteLogin_LoggedIn(Object sender, LoginCancelEventArgs e) +46
System.Web.UI.WebControls.Login.OnLoggedIn(LoginCancelEventArgs e) +105

(sorry, I kept the stack trace but my cat switched the laptop off before I was able to post the message..)

--

I also tried changing the pc locale from it-IT to en-US and restarting iis, suspecting a datetime.parse issue with localized content, but that seems not the case.

 

8/14/2007 6:44:04 AM
Gravatar
Total Posts 18439

Re: "String was not recognized as a valid DateTime." at login time

Hi Federico,

I still suspect this issue is related to localization. Under the default settings in Web.config, the executing thread is set to the culture of the browser as determined by the language preference in the browser. I did not expect this kind of error converting a datetime field to a datetime obect but apparently looks like Sqlite stores them internal as string so formatting is used to convert and something isn't matching up right.

Are you using the pre-populated db included with mojoPortal? Perhaps because the data was created on my system in en-US the formatting isn't right.

Can you try creating a new db from scratch and see if you get the same result? Perahps by creating it on your system it wil have the correct format when the data is created.

Hope it helps,

Joe

8/14/2007 12:23:00 PM
Gravatar
Total Posts 22

Re: "String was not recognized as a valid DateTime." at login time

Hi Joe,

no, I did not modify the localization settings in the web.config, I should have thought about it. I will make some experiment and let you know tomorrow.
I will also try creating the db from scratch (yes, I used the pre-populated one).
I know very little about SQLite, but I know that the only date type it knows is string, and that in its philosophy its not up to the db to care about it. I would expect anyway the Mono library to handle the conversion without being culture-sensitive, both on storing and retrieving data... I'm not sure what's the right behavior to expect from it and whether we should report a bug to the mono guys.

I will let you know more tomorrow, thank you for the reply.

Federico

8/15/2007 6:51:27 AM
Gravatar
Total Posts 22

Re: "String was not recognized as a valid DateTime." at login time

Hi Joe,
I drilled a little down the issue, an found something interesting.

I downloaded a tool to inspect the SQLite database file, and noted that:

select LastActivityDate, DateCreated from mp_users

LastActivityDate 2007-08-15 08.22.49 (it-IT format)
DateCreated 2007-08-13 21:20:50 (en-US format)

the two dates where written (as text, as sqlite does) with two different formatting.

changing the record with:
update mp_users set LastActivityDate = "2007-08-15 08:22:49"
I was able to login

you were right stating that this is a localization issue, in fact changing in the web.config
<globalization culture="auto:en-US"
to
<globalization culture="en-US"
bypassed the problem.
but I wanted to go deeper. I restored the auto: prefix


from sourcecode\mojoportal\mojoPortal.Business\SiteUser.cs
method mojoPortal.Business.SiteUser.GetUser(IDataReader)
try
{
if (reader["LastActivityDate"] != DBNull.Value)
{
this.lastActivityDate = (DateTime)reader["LastActivityDate"];
}
}
catch (InvalidCastException ex)
{
if (log.IsErrorEnabled)
{
log.Error("LastActivityDate was invalid", ex);
}
}
but the actual exception is of type FormatException

I try to create the db from scratch, with all my original local settings; the setup runs fine, but when I
click the "Site Home Page" link I get the usual stack trace (does it try to fetch the admin data?).

select LastActivityDate, DateCreated from mp_users

LastActivityDate None
DateCreated "2007-08-15 09.43.04" (it-IT format)

my first guess was that, no matter how it has been inserted, the Mono library is not able to retrieve date data in non-us format (with dots instead of columns).

some more experiment:
i try again to create the db from scratch. Of course the db population is performed by MojoPortal, not the script. All my settings are italian, apart the preferred language of the browser (Firefox), which I set to en-US; the db is created correctly, and this time DateCreated value is in en-US format.
I can login
OK. I understand that the db population is probably performed with the culture matching the locale sported by the browser at setup time.
what if I change the browser language?
I change Moz's settings to en-US, I try to login (I open another browser instance to be sure), and voilà, here is the exception again.
In the db the fields are again in en-US format, but they are not fetched correctly, so I guess that the Mono library attempts to parse them by using the CurrentCulture format.

I had a look at SQLiteConvert.cs at method
public DateTime ToDateTime(string dateText)
{
switch (_datetimeFormat)
{
case SqliteDateFormats.Ticks:
return new DateTime(Convert.ToInt64(dateText, CultureInfo.InvariantCulture));
default:
return DateTime.ParseExact(dateText, _datetimeFormats, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None);
}
}
_datetimeFormats is an array of expected formats, and is defined as
/// <summary>
/// An array of ISO8601 datetime formats we support conversion from
/// </summary>
private static string[] _datetimeFormats = new string[] {
"yyyy-MM-dd HH:mm:ss.fffffff",
"yyyy-MM-dd HH:mm:ss",
"yyyy-MM-dd HH:mm",
"yyyyMMddHHmmss",
"yyyyMMddHHmm",
"yyyyMMddTHHmmssfffffff",
"yyyy-MM-dd",
"yy-MM-dd",
"yyyyMMdd",
"HH:mm:ss",
"HH:mm",
"THHmmss",
"THHmm",
"yyyy-MM-dd HH:mm:ss.fff",
"yyyy-MM-ddTHH:mm",
"yyyy-MM-ddTHH:mm:ss",
"yyyy-MM-ddTHH:mm:ss.fff",
"yyyy-MM-ddTHH:mm:ss.ffffff",
"HH:mm:ss.fff"
};
so in my understanding the db field should never, ever be populated with a datetime string formatted with dots as in italian culture.
I'm not sure why changing Firefox language back to italian caused the parsing to fail, since it uses DateTimeFormatInfo.InvariantInfo and the field format in the db is now "yyyy-MM-dd HH:mm".
Unfortunately I can't debug it to better understand it.

I did not find anything about datetime data type in the sqlite.org site; the script runs fine so I guess that when an unknown data type is met, sqlite just treat it as plain text.

The real bug is in my opinion located where the data is persisted.
Unfortunately it makes the "auto:" feature unusable, because a user might try to access from different browsers from different locations.

The bug is probably in the Mono library, but you may work it around by temporarely setting the CurrentCulture to something neutral when persisting data.

hope this helps
Federico.

8/15/2007 6:54:54 AM
Gravatar
Total Posts 22

Re: "String was not recognized as a valid DateTime." at login time

Hi Joe, I have something else to point out.

The issue is more serious then it appeared at first sight: after the notification of the datetime exception, also an unhandled exception occurs, which causes the asp_net.wp to stop.

This means that if the problem occurs to a single user, it would break the entire asp.net server.

My event log is crowded with pairs of event notifications: an error "aspnet_wp.exe (PID: 1140) stopped unexpectedly." and a warning:

Event code: 3005
Event message: An unhandled exception has occurred.
Event time: 15/08/2007 12.51.15
Event time (UTC): 15/08/2007 10.51.15
Event ID: dc3d429691184ec69719f69223baf12f
Event sequence: 20
Event occurrence: 1
Event detail code: 0

Application information:
Application domain: /LM/W3SVC/1/Root/MojoSQLite-1-128316480880000000
Trust level: Full
Application Virtual Path: /MojoSQLite
Application Path: c:\inetpub\wwwroot\MojoSQLite\
Machine name: FRED-MOBILE

Process information:
Process ID: 2064
Process name: aspnet_wp.exe
Account name: FRED-MOBILE\ASPNET

Exception information:
Exception type: HttpUnhandledException
Exception message: Exception of type 'System.Web.HttpUnhandledException' was thrown.

Request information:
Request URL: http://localhost/MojoSQLite/Secure/Login.aspx
Request path: /MojoSQLite/Secure/Login.aspx
User host address: 127.0.0.1
User:
Is authenticated: False
Authentication Type:
Thread account name: FRED-MOBILE\ASPNET

Thread information:
Thread ID: 1
Thread account name: FRED-MOBILE\ASPNET
Is impersonating: False
Stack trace: at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at ASP.secure_login_aspx.ProcessRequest(HttpContext context)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

I have not been able to track this last problem any better.

Federico

8/15/2007 7:13:16 AM
Gravatar
Total Posts 18439

Re: "String was not recognized as a valid DateTime." at login time

Hi Federico,

You are working with the source code right?

I found a place in my SQLiteHelper.cs ExecuteNonQuery:

foreach (IDataParameter p in commandParameters)
{
if (p.DbType == DbType.DateTime)
{
p.DbType = DbType.String;
p.Value = ((DateTime)p.Value).ToString("yyyy-MM-dd HH:mm:ss");
}
cmd.Parameters.Add( p );
}

Can you comment that out like this and try it with a new db and see if it solves it?

foreach (IDataParameter p in commandParameters)
{
//if (p.DbType == DbType.DateTime)
//{
// p.DbType = DbType.String;
// p.Value = ((DateTime)p.Value).ToString("yyyy-MM-dd HH:mm:ss");
//}
cmd.Parameters.Add( p );
}

This may have been a needed hack for the old Mono.Data.SqliteClient. I commented it out on my system and it still seems to work ok so maybe that is the cause of the problem since it is changing to string there.

Joe

8/15/2007 7:22:18 AM
Gravatar
Total Posts 18439

Re: "String was not recognized as a valid DateTime." at login time

ps, there are several places in the file where this would need to be commented out.

Joe

8/15/2007 9:29:00 AM
Gravatar
Total Posts 22

Re: "String was not recognized as a valid DateTime." at login time

Hi Joe,

actually not, I'm working with the release version because I do not have VS2005 (I have the Express edition only), but I had a look at the source code.

May be I'll be able to compile the Mono library alone.

Federico

8/15/2007 9:33:22 AM
Gravatar
Total Posts 18439

Re: "String was not recognized as a valid DateTime." at login time

Hi Federico,

I'll compile it for you and send it for you to test later today (2-3 hours from now I will have a chance)

Thanks,

Joe

8/15/2007 1:27:33 PM
Gravatar
Total Posts 22

Re: "String was not recognized as a valid DateTime." at login time

Hi Joe, i just tried your newly compiled dll with the SQLite version of the test portal.

Both using the original database and creating a brand new one and populating using italian as preferred language in the browser do work fine: I can log in with no exceptions raising. also the unhandled exception that halted the entire site (happened when restarting the site durin tear down and also in other cases) is not experienced any more.

one thing that changes in the way the date datum is persisted is the tostring format which now is "yyyy-MM-dd HH:mm:ss.fffffff" (e.g "2007-08-15 18:12:57.5937500"). i don't know if it will have any side-effect.

Federico

8/15/2007 1:43:50 PM
Gravatar
Total Posts 18439

Re: "String was not recognized as a valid DateTime." at login time

Hi Federico,

Excellent! So that fixed it. I don't think there will be any side effect, that looks like the correct way to store it in the db. Please let me know anything else you find in testing. I will go ahead and  make a new download for Sqlite.

Thanks,

Joe

You must sign in to post in the forums. This thread is closed to new posts.