Differences in implementation messing up DateTimes on Mono

Code junkies hangout here

Moderators: ChrisThornett, LXF moderators

Differences in implementation messing up DateTimes on Mono

Postby nerdmaster » Mon Mar 29, 2010 3:14 pm

I'm working on an ASP.NET application (2.0) and I'm hoping to deploy it on a Debian server running xsp2. Application runs fine so far on my development box running XP/IIS but when I test it out on the Debian box I get the following error:

"String was not recognized as a valid DateTime."

I suspect the offending code is part of a DataBinding event for a Repeater control which sets the text of a literal control.

A datetime is pulled from a mysql database and gets bound to the literal control in the template. The binding event serves to format the date:

protected void litRecentBlog_DataBinding(object sender, EventArgs e)
{
Literal lit = sender as Literal
if(lit != null)
lit.Text = Convert.ToDateTime(lit.Text).ToString( "ddd MMM dd yyyy" );
}


This works perfectly on XP/IIS (using the official .NET framework) and produces meaningful dates. Because of this I suspect there is something strange going on with the implementation of DateTime in Mono.

Does anyone know if there are any issues surrounding this or any other classes in Mono? I'd hate to think that I wouldn't be able to run my website on a Linux based machine.
nerdmaster
 
Posts: 52
Joined: Thu Jul 14, 2005 10:18 am

Postby ollie » Mon Mar 29, 2010 10:12 pm

Not really into mono but there does seem to be a bug in DateTime:

http://lists.ximian.com/pipermail/mono-devel-list/2010-March/034240.html

HTH
User avatar
ollie
Moderator
 
Posts: 2749
Joined: Mon Jul 25, 2005 11:26 am
Location: Bathurst NSW Australia

Postby nerdmaster » Tue Mar 30, 2010 11:55 am

I'm not using the TryParseExact method but if they have a problem with one method it isn't such a stretch of the imagination to think that others may be at fault.

Here is where things get really interesting. Here is the code (from the designer) for the part that's failing:

Code: Select all
        <h2>Latest Blog:</h2>
      <asp:Repeater runat="server" ID="blogUpdates" DataSourceID="blogUpdateDataSource">
          <ItemTemplate>
             <p>
                 <strong>
                        <asp:Literal ID="litRecentBlog" Text='<%# Eval("blog_date") %>' OnDataBinding="litRecentBlog_DataBinding" runat="server"></asp:Literal>
                    </strong>
                    <br />
                 <%# Eval("title") %>
             </p>
         </ItemTemplate>
      </asp:Repeater>
      <asp:ObjectDataSource ID="blogUpdateDataSource" runat="server"
            SelectMethod="getBloglatest" TypeName="DALBlog"></asp:ObjectDataSource>


I used the getBlogLatest method in a simple console application so I could see what was being produced (first without a Convert.ToDateTime and second with)

Code: Select all
DataTable dateTable = DALBlog.GetBlogLatest();
         foreach( DataRow row in dateTable.Rows )
            Console.WriteLine(Convert.ToDateTime(row["blog_date"]).ToString("ddd MMM dd yyyy") + " " + row["blog_date"]);


Surprisingly it works - not sure if I'm oversimplifying it
nerdmaster
 
Posts: 52
Joined: Thu Jul 14, 2005 10:18 am

Postby nerdmaster » Tue Mar 30, 2010 12:44 pm

I think I have it figured out. It was unable to parse the text because there is no text. When performing the OnDataBinding event there is no data bound. A significant difference it would seem.

Not sure on the best way to approach this. I'm thinking assign the date value to a hiddenfield and reference this in the OnDataBinding event for the Literal.

UPDATE - I simply shifted it from the OnDataBinding method to the OnPreRender method.

Fixed this problem but I can see it being a problem when it comes to using the OnDataBinding method to manipulate the presentation of information in things like gridviews. Already starting to get a little skeptical using Mono (shame because I REALLY don't want to have to host this on a windows box)
nerdmaster
 
Posts: 52
Joined: Thu Jul 14, 2005 10:18 am

Postby AndyBaxman » Wed Mar 31, 2010 8:43 am

You need to be really careful because ASP.NET is proprietary Microsoft technology. Many features of MS ASP.NET are not implemented in MONO ASP.NET or are implemented and behave differently.

Even with Java, where there are official runtimes and JDKs for Windows and Linux, porting from IIS/Windows to Apache/Linux is less than reliable.

With .NET you should either develop and deploy on Linux (Mono) or develop and deploy on Windows.
Bomb #20: "Let there be light"
User avatar
AndyBaxman
LXF regular
 
Posts: 523
Joined: Tue Oct 04, 2005 8:47 am

Postby nerdmaster » Thu Apr 01, 2010 12:22 am

AndyBaxman wrote:You need to be really careful because ASP.NET is proprietary Microsoft technology. Many features of MS ASP.NET are not implemented in MONO ASP.NET or are implemented and behave differently.

Even with Java, where there are official runtimes and JDKs for Windows and Linux, porting from IIS/Windows to Apache/Linux is less than reliable.

With .NET you should either develop and deploy on Linux (Mono) or develop and deploy on Windows.


Good point, although it should prove to be an interesting exercise in learning the differences between the two platforms. If need be I guess I'll have to host it on an MS platform as those are the skills I need to keep in check (sadly an ASP.NET developer by trade, and it's the area with the most opportunities) but provided I can work around the differences (depending upon how many there are) I *might* be able to stick with a linux server for deployment (I say deployment, really it'll be hosted in my own network just as a showcase)
nerdmaster
 
Posts: 52
Joined: Thu Jul 14, 2005 10:18 am


Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron