This project is read-only.

Invalid DateTime

May 7, 2012 at 11:35 PM

I've installed BE version 2.6 RC and after logged in, I opened the Dashboard and get this error:

Row 127:
Row 128:@helper GetLatestPackages(){
Row 129:    var packages = PackageRepository.FromGallery("all", 0, Gallery.OrderType.Newest);
Row 130:    
Row 131:    if(packages != null && packages.Count() > 0){

Source File: c:\inetpub\wwwroot\webaspx\blogengine-rc\App_Code\Helpers\DashboardHelper.cshtml    Row: 129

Stack Trace

[FormatException: Stringa non riconosciuta come valore DateTime valido.]
   System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles) +10071278
   System.Convert.ToDateTime(String value, IFormatProvider provider) +72
   BlogEngine.Core.Packaging.<>c__DisplayClass11.b__6(JsonPackage p) in J:\Projects\BlogEngine_2_6_0_0\Source\BlogEngine\BlogEngine.Core\Packaging\PackageRepository.cs:72
   System.Linq.EnumerableSorter`2.ComputeKeys(TElement[] elements, Int32 count) +78
   System.Linq.EnumerableSorter`1.Sort(TElement[] elements, Int32 count) +21
   System.Linq.d__0.MoveNext() +178
   System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +381
   System.Linq.Enumerable.ToList(IEnumerable`1 source) +58
   BlogEngine.Core.Packaging.PackageRepository.FromGallery(String pkgType, Int32 page, OrderType sortOrder, String searchVal) in J:\Projects\BlogEngine_2_6_0_0\Source\BlogEngine\BlogEngine.Core\Packaging\PackageRepository.cs:72
   ASP.Helpers.DashboardHelper.b__16(TextWriter __razor_helper_writer) in c:\inetpub\wwwroot\webaspx\blogengine-rc\App_Code\Helpers\DashboardHelper.cshtml:129
   System.Web.WebPages.HelperResult.WriteTo(TextWriter writer) +10
   System.Web.WebPages.WebPageBase.Write(HelperResult result) +71
   ASP._Page_admin_default_cshtml.Execute() in c:\inetpub\wwwroot\webaspx\blogengine-rc\admin\default.cshtml:58
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +197
   System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors) +69
   System.Web.WebPages.WebPage.ExecutePageHierarchy() +151
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +76
   System.Web.WebPages.WebPageHttpHandler.ProcessRequestInternal(HttpContext context) +249

Is there something wrong with my configuration?

Thanks in advance, have a nice day! :-)

May 7, 2012 at 11:51 PM

Well, in the page DashboardHelper.cshtml on row 129, if I change the value Gallery.OrderType. from Newest to any other value, like Alphanumeric, Downloads or Rating, it works!


May 11, 2012 at 6:55 PM

Same problem.


May 11, 2012 at 7:59 PM

Does list in the Dashboard works for you guys? It also sorted on date, but probably uses different sorting code. If it works, I could look and change it to use same code as dashboard. Problem here is that I can't reproduce it locally because it is probably combination of your server locale plus client machine/browser locals and settings that causes issue, so I would need help verifying it works. For me it is fine even if I switch language in admin/settings or my browser.

May 11, 2012 at 9:20 PM
Edited May 11, 2012 at 9:22 PM

 Hi rtur.
My cultureinfo is es-ES.
The method that throws the error is FromGallery (PackageRepository class). Convert.ToDateTime not know interpret the date correctly:

case Gallery.OrderType.Newest:
	packages = packages.OrderByDescending(p => Convert.ToDateTime(p.LastUpdated, culture)).ThenBy(p => p.Title).ToList();

I think the problem is in the Utils.GetDefaultCulture() method.

My solution was change to culture InvariantCulture: 

        public static CultureInfo GetDefaultCulture()
            var settingsCulture = BlogSettings.Instance.Culture;
            if (Utils.StringIsNullOrWhitespace(settingsCulture) ||
                settingsCulture.Equals("Auto", StringComparison.OrdinalIgnoreCase))
                return CultureInfo.InvariantCulture;

            return CultureInfo.CreateSpecificCulture(settingsCulture);

Regards and thanks! 



May 12, 2012 at 12:55 PM

It's strange... I have installed BE on another local host machine, and it doesn't seems to be any error!!

Do you think that the solution proposed by @GabrielGI could be useful to prevent this error?

Thanks, and have a nice day! :)

May 12, 2012 at 6:29 PM

I made a change for gallery sorting to use invariant culture regardless, this should work for all cases. It is in for 2.6 final release.

May 12, 2012 at 6:39 PM

Thanks a lot rtur! :)