Bug 22349 - DateTimeOffset Could not convert constant expression to string
Summary: DateTimeOffset Could not convert constant expression to string
Status: RESOLVED FEATURE
Alias: None
Product: Class Libraries
Classification: Mono
Component: General ()
Version: unspecified
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2014-08-25 18:25 UTC by John Miller [MSFT]
Modified: 2014-09-02 12:52 UTC (History)
5 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Test Case (19.37 KB, application/zip)
2014-08-25 18:25 UTC, John Miller [MSFT]
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FEATURE

Description John Miller [MSFT] 2014-08-25 18:25:27 UTC
Created attachment 7791 [details]
Test Case

**Overview:**

   The attached sample throws an exception when evaluating a linq expression with DateTimeOffset.

**Steps to Reproduce:**

   1. Run the attached sample

**Actual Results:**

>{System.InvalidOperationException: Could not convert constant 8/24/2014 5:21:21 PM +00:00 expression to string. at System.Data.Services.Client.ExpressionWriter.VisitConstant (System.Linq.Expressions.ConstantExpression c) [0x00032] in >///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.104/src/mono/mcs/class/System.Data.Services.Client/Client/System/Data/Services/Client/ALinq/ExpressionWriter.cs:213 at System.Data.Services.Client.ExpressionVisitor.Visit (System.Linq.Expressions.Expression exp) [0x00106] in >///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.104/src/mono/mcs/class/System.Data.Services.Client/Client/System/Data/Services/Client/ALinq/ExpressionVisitor.cs:147 at System.Data.Services.Client.DataServiceExpressionVisitor.Visit (System.Linq.Expressions.Expression exp) [0x00067] in >///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.104/src/mono/mcs/class/System.Data.Services.Client/Client/System/Data/Services/Client/ALinq/DataServiceExpressionVisitor.cs:40 at System.Data.Services.Client.ExpressionWriter.Visit (System.Linq.Expressions.Expression exp) [0x0001d] in >///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.104/src/mono/mcs/class/System.Data.Services.Client/Client/System/Data/Services/Client/ALinq/ExpressionWriter.cs:67 at System.Data.Services.Client.ExpressionWriter.VisitOperand (System.Linq.Expressions.Expression e) [0x0003f] in >///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.104/src/mono/mcs/class/System.Data.Services.Client/Client/System/Data/Services/Client/ALinq/ExpressionWriter.cs:398 at System.Data.Services.Client.ExpressionWriter.VisitBinary (System.Linq.Expressions.BinaryExpression b) [0x00214] in >///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.104/src/mono/mcs/class/System.Data.Services.Client/Client/System/Data/Services/Client/ALinq/ExpressionWriter.cs:334 at System.Data.Services.Client.ExpressionVisitor.Visit (System.Linq.Expressions.Expression exp) [0x000df] in >///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.104/src/mono/mcs/class/System.Data.Services.Client/Client/System/Data/Services/Client/ALinq/ExpressionVisitor.cs:141 at System.Data.Services.Client.DataServiceExpressionVisitor.Visit (System.Linq.Expressions.Expression exp) [0x00067] in >///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.104/src/mono/mcs/class/System.Data.Services.Client/Client/System/Data/Services/Client/ALinq/DataServiceExpressionVisitor.cs:40 at System.Data.Services.Client.ExpressionWriter.Visit (System.Linq.Expressions.Expression exp) [0x0001d] in >///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.104/src/mono/mcs/class/System.Data.Services.Client/Client/System/Data/Services/Client/ALinq/ExpressionWriter.cs:67 at System.Data.Services.Client.ExpressionWriter.VisitOperand (System.Linq.Expressions.Expression e) [0x00024] in >///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.104/src/mono/mcs/class/System.Data.Services.Client/Client/System/Data/Services/Client/ALinq/ExpressionWriter.cs:393 at System.Data.Services.Client.ExpressionWriter.VisitBinary (System.Linq.Expressions.BinaryExpression b) [0x00214] in >///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.104/src/mono/mcs/class/System.Data.Services.Client/Client/System/Data/Services/Client/ALinq/ExpressionWriter.cs:334 at System.Data.Services.Client.ExpressionVisitor.Visit (System.Linq.Expressions.Expression exp) [0x000df] in >///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.104/src/mono/mcs/class/System.Data.Services.Client/Client/System/Data/Services/Client/ALinq/ExpressionVisitor.cs:141 at System.Data.Services.Client.DataServiceExpressionVisitor.Visit (System.Linq.Expressions.Expression exp) [0x00067] in >///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.104/src/mono/mcs/class/System.Data.Services.Client/Client/System/Data/Services/Client/ALinq/DataServiceExpressionVisitor.cs:40 at System.Data.Services.Client.ExpressionWriter.Visit (System.Linq.Expressions.Expression exp) [0x0001d] in >///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.104/src/mono/mcs/class/System.Data.Services.Client/Client/System/Data/Services/Client/ALinq/ExpressionWriter.cs:67 at System.Data.Services.Client.ExpressionWriter.VisitOperand (System.Linq.Expressions.Expression e) [0x00024] in >///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.104/src/mono/mcs/class/System.Data.Services.Client/Client/System/Data/Services/Client/ALinq/ExpressionWriter.cs:393 at System.Data.Services.Client.ExpressionWriter.VisitBinary (System.Linq.Expressions.BinaryExpression b) [0x00000] in >///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.104/src/mono/mcs/class/System.Data.Services.Client/Client/System/Data/Services/Client/ALinq/ExpressionWriter.cs:274 at System.Data.Services.Client.ExpressionVisitor.Visit (System.Linq.Expressions.Expression exp) [0x000df] in >///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.104/src/mono/mcs/class/System.Data.Services.Client/Client/System/Data/Services/Client/ALinq/ExpressionVisitor.cs:141 at System.Data.Services.Client.DataServiceExpressionVisitor.Visit (System.Linq.Expressions.Expression exp) [0x00067] in >///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.104/src/mono/mcs/class/System.Data.Services.Client/Client/System/Data/Services/Client/ALinq/DataServiceExpressionVisitor.cs:40 at System.Data.Services.Client.ExpressionWriter.Visit (System.Linq.Expressions.Expression exp) [0x0001d] in >///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.104/src/mono/mcs/class/System.Data.Services.Client/Client/System/Data/Services/Client/ALinq/ExpressionWriter.cs:67 at System.Data.Services.Client.ExpressionWriter.Translate (System.Linq.Expressions.Expression e) [0x00000] in >///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.104/src/mono/mcs/class/System.Data.Services.Client/Client/System/Data/Services/Client/ALinq/ExpressionWriter.cs:404 at System.Data.Services.Client.ExpressionWriter.ExpressionToString (System.Data.Services.Client.DataServiceContext context, System.Linq.Expressions.Expression e) [0x00007] in >///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.104/src/mono/mcs/class/System.Data.Services.Client/Client/System/Data/Services/Client/ALinq/ExpressionWriter.cs:54 at System.Data.Services.Client.UriWriter.ExpressionToString (System.Linq.Expressions.Expression expression) [0x00000] in >///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.104/src/mono/mcs/class/System.Data.Services.Client/Client/System/Data/Services/Client/ALinq/UriWriter.cs:408 at System.Data.Services.Client.UriWriter.VisitQueryOptionExpression (System.Data.Services.Client.FilterQueryOptionExpression fqoe) [0x0002d] in >///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.104/src/mono/mcs/class/System.Data.Services.Client/Client/System/Data/Services/Client/ALinq/UriWriter.cs:297 at System.Data.Services.Client.UriWriter.VisitQueryOptions (System.Data.Services.Client.ResourceExpression re) [0x000b6] in >///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.104/src/mono/mcs/class/System.Data.Services.Client/Client/System/Data/Services/Client/ALinq/UriWriter.cs:219 at System.Data.Services.Client.UriWriter.VisitResourceSetExpression (System.Data.Services.Client.ResourceSetExpression rse) [0x001b7] in >///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.104/src/mono/mcs/class/System.Data.Services.Client/Client/System/Data/Services/Client/ALinq/UriWriter.cs:182 at System.Data.Services.Client.DataServiceExpressionVisitor.Visit (System.Linq.Expressions.Expression exp) [0x00040] in >///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.104/src/mono/mcs/class/System.Data.Services.Client/Client/System/Data/Services/Client/ALinq/DataServiceExpressionVisitor.cs:34 at System.Data.Services.Client.UriWriter.Translate (System.Data.Services.Client.DataServiceContext context, Boolean addTrailingParens, System.Linq.Expressions.Expression e, >System.Uri& uri, System.Version& version) [0x0001f] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.104/src/mono/mcs/class/System.Data.Services.Client/Client/System/Data/Services/Client/ALinq/UriWriter.cs:49 at System.Data.Services.Client.DataServiceQueryProvider.Translate (System.Linq.Expressions.Expression e) [0x00035] in >///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.104/src/mono/mcs/class/System.Data.Services.Client/Client/System/Data/Services/Client/ALinq/DataServiceQueryProvider.cs:125 at System.Data.Services.Client.DataServiceQuery`1[System.Int32].Translate () [0x0000b] in >///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.104/src/mono/mcs/class/System.Data.Services.Client/Client/System/Data/Services/Client/DataServiceQueryOfT.cs:197 at System.Data.Services.Client.DataServiceQuery`1[System.Int32].get_QueryComponents () [0x00000] in >///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.104/src/mono/mcs/class/System.Data.Services.Client/Client/System/Data/Services/Client/DataServiceQueryOfT.cs:87 at System.Data.Services.Client.DataServiceRequest.GetQuerySetCount (System.Data.Services.Client.DataServiceContext context) [0x00000] in >///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.104/src/mono/mcs/class/System.Data.Services.Client/Client/System/Data/Services/Client/DataServiceRequest.cs:155 at System.Data.Services.Client.DataServiceQueryProvider.ReturnSingleton[Int32] (System.Linq.Expressions.Expression expression) [0x00095] in >///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.104/src/mono/mcs/class/System.Data.Services.Client/Client/System/Data/Services/Client/ALinq/DataServiceQueryProvider.cs:98 at System.Data.Services.Client.DataServiceQueryProvider.Execute[Int32] (System.Linq.Expressions.Expression expression) [0x0000c] in >///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.104/src/mono/mcs/class/System.Data.Services.Client/Client/System/Data/Services/Client/ALinq/DataServiceQueryProvider.cs:70 at System.Linq.Queryable.Execute[Int32,JointServoOffEvent] (IQueryable`1 source, System.Reflection.MethodBase current) [0x00000] in >///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.104/src/mono/mcs/class/System.Core/System.Linq/Queryable.cs:55 at System.Linq.Queryable.Count[JointServoOffEvent] (IQueryable`1 source) [0x00006] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.104/src/mono/mcs/class/System.Core/System.Linq/Queryable.cs:446 at >iPhone.iRConnect.RobotDashboardGadgets.RobotMotionGadget.UpdateHTMLContent () [0x00480] in /Users/eckertia/Projects/Projects/ZDT/iRConnect/iPhone.iRConnect/RobotDashboardGadgets/RobotMotionGadget.cs:116 } System.InvalidOperationException

**Expected Results:**

   No crash, statement is evaluated successfully. 

**Build Date & Platform:**

   Mono 3.6
   XI 7.2.6
Comment 1 Marek Safar 2014-08-26 04:01:16 UTC
This is System.Data.Services.Client limitation. Exactly same error happens on .net.

Comparing Ticks instead workarounds the issue for me

Suggested change

RobotControllerStatus status = dataClient.RobotControllerStatus.Where (st => st.last_updated.Ticks > limit.Ticks).FirstOrDefault ();
Comment 2 Isaac.Eckert 2014-09-02 11:07:09 UTC
The ticks property does not work unless you know that the offset in the database is the same as the offset in code.  This is not an acceptable solution for the DateTimeOffset type which allows different offsets to be stored in the database.

Further, Microsoft's latest Web API appears to only support DateTimeOffset.  I read in the forums that limitation has been fixed in Microsoft's implementation.  I will have to test it later.

Since I have to have this working by tomorrow, I will build the query string manually.


I found this article:

http://technet.microsoft.com/en-us/evalcenter/ee373845(v=vs.85).aspx

*****************************
OData defines the following new data types, which are supported by WCF Data Services: 

-Geospatial Types* ...

-DateTimeOffset

-TimeSpan
Comment 3 Marek Safar 2014-09-02 11:14:23 UTC
If you think it was fixed in Microsoft latest API you can just grab Microsoft.Data.Services.Client nuget and use it instead
Comment 4 Isaac.Eckert 2014-09-02 12:52:32 UTC
It appears I have two package choices.

The first package did not install so I guess it is the wrong choice.

"Could not install package 'System.Spatial 5.0.1'. You are trying to install this package into a project that targets 'MonoTouch,Version=v1.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author."

The second package installed but it is the Silverlight version.  Unfortunately, I did not write my code using Silverlight Async methods so I cannot easily upgrade.  I will try this after the show.  

Also, it is not clear how to reimplement the missing connection Timeout property in the "new" version.  It was removed.