Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Differences in implementation messing up DateTimes on Mono

 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming
View previous topic :: View next topic  
Author Message
nerdmaster



Joined: Thu Jul 14, 2005 11:18 am
Posts: 52

PostPosted: Mon Mar 29, 2010 4:14 pm    Post subject: Differences in implementation messing up DateTimes on Mono Reply with quote

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:

Quote:
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.
Back to top
View user's profile Send private message
ollie
Moderator


Joined: Mon Jul 25, 2005 12:26 pm
Posts: 2749
Location: Bathurst NSW Australia

PostPosted: Mon Mar 29, 2010 11:12 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
nerdmaster



Joined: Thu Jul 14, 2005 11:18 am
Posts: 52

PostPosted: Tue Mar 30, 2010 12:55 pm    Post subject: Reply with quote

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:
        <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:
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
Back to top
View user's profile Send private message
nerdmaster



Joined: Thu Jul 14, 2005 11:18 am
Posts: 52

PostPosted: Tue Mar 30, 2010 1:44 pm    Post subject: Reply with quote

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)
Back to top
View user's profile Send private message
AndyBaxman
LXF regular


Joined: Tue Oct 04, 2005 9:47 am
Posts: 523

PostPosted: Wed Mar 31, 2010 9:43 am    Post subject: Reply with quote

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"
Back to top
View user's profile Send private message
nerdmaster



Joined: Thu Jul 14, 2005 11:18 am
Posts: 52

PostPosted: Thu Apr 01, 2010 1:22 am    Post subject: Reply with quote

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)
Back to top
View user's profile Send private message
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast