I’m getting a strange exception in my code using LINQ.
Invalid cast from 'System.UInt32' to 'System.Nullable`1[[System.UInt32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]'.
the line that caused this was this code:
if CheckRes.Count>0 then
rq := (from rrec in fDataModule.DataAdapter.GetTable<lpv8oelib.PSQLSchema.aprecon>
where (CheckRes.Contains(rrec.ReconID)) and (rrec.PostDateTime<>zdouble)
select rrec).ToList;
The strange thing is that CheckRes is a List of Nullable UInt32 and ReconID is a nullable UInt32, and there is no explicit cast done.
do you have a callstack? I have a feeling this might actually be a DA issue, not a compiler issue. I checked the generated code but for whatever combination I do, it seems to validate fine on the code itself.
I’m going to invite @antonk to this conversation, maybe he knows more.
Please provide a full callstack for the exception occurred, table definition class for the table used and CheckRes definition (you can drop this information to support@ if you don’t want to disclose it).
Invalid cast from 'System.UInt32' to 'System.Nullable`1[[System.UInt32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]'.
---------------------------------------------------------
at System.Convert.DefaultToType(IConvertible value, Type targetType, IFormatProvider provider)
at System.UInt32.System.IConvertible.ToType(Type type, IFormatProvider provider)
at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
at RemObjects.DataAbstract.Linq.QueryBinder.BindContains(Expression source, Expression match, Boolean isRoot) in c:\CI\b\rofx\932\Data Abstract for .NET\Source\RemObjects.DataAbstract\Linq\QueryBinder.pas:line 1188
at RemObjects.DataAbstract.Linq.QueryBinder.VisitMethodCall(MethodCallExpression val) in c:\CI\b\rofx\932\Data Abstract for .NET\Source\RemObjects.DataAbstract\Linq\QueryBinder.pas:line 442
at RemObjects.DataAbstract.Linq.ExpressionVisitor.Visit(Expression val) in c:\CI\b\rofx\932\Data Abstract for .NET\Source\RemObjects.DataAbstract\Linq\ExpressionVisitor.pas:line 127
at RemObjects.DataAbstract.Linq.QueryBinder.Visit(Expression val) in c:\CI\b\rofx\932\Data Abstract for .NET\Source\RemObjects.DataAbstract\Linq\QueryBinder.pas:line 926
at RemObjects.DataAbstract.Linq.QueryBinder.VisitBinary(BinaryExpression val) in c:\CI\b\rofx\932\Data Abstract for .NET\Source\RemObjects.DataAbstract\Linq\QueryBinder.pas:line 829
at RemObjects.DataAbstract.Linq.ExpressionVisitor.Visit(Expression val) in c:\CI\b\rofx\932\Data Abstract for .NET\Source\RemObjects.DataAbstract\Linq\ExpressionVisitor.pas:line 121
at RemObjects.DataAbstract.Linq.QueryBinder.Visit(Expression val) in c:\CI\b\rofx\932\Data Abstract for .NET\Source\RemObjects.DataAbstract\Linq\QueryBinder.pas:line 926
at RemObjects.DataAbstract.Linq.QueryBinder.BindWhere(Type aResultType, Expression aSource, LambdaExpression aPredicate) in c:\CI\b\rofx\932\Data Abstract for .NET\Source\RemObjects.DataAbstract\Linq\QueryBinder.pas:line 578
at RemObjects.DataAbstract.Linq.QueryBinder.VisitMethodCall(MethodCallExpression val) in c:\CI\b\rofx\932\Data Abstract for .NET\Source\RemObjects.DataAbstract\Linq\QueryBinder.pas:line 408
at RemObjects.DataAbstract.Linq.ExpressionVisitor.Visit(Expression val) in c:\CI\b\rofx\932\Data Abstract for .NET\Source\RemObjects.DataAbstract\Linq\ExpressionVisitor.pas:line 127
at RemObjects.DataAbstract.Linq.QueryBinder.Visit(Expression val) in c:\CI\b\rofx\932\Data Abstract for .NET\Source\RemObjects.DataAbstract\Linq\QueryBinder.pas:line 926
at RemObjects.DataAbstract.Linq.RemoteTable`1.MakeProjection(Expression expression) in c:\CI\b\rofx\932\Data Abstract for .NET\Source\RemObjects.DataAbstract\Linq\RemoteTable.pas:line 367
at RemObjects.DataAbstract.Linq.RemoteTable`1.Translate(Expression expression) in c:\CI\b\rofx\932\Data Abstract for .NET\Source\RemObjects.DataAbstract\Linq\RemoteTable.pas:line 303
at RemObjects.DataAbstract.Linq.RemoteTable`1.Execute(Expression expression, DataParameter[] parameters) in c:\CI\b\rofx\932\Data Abstract for .NET\Source\RemObjects.DataAbstract\Linq\RemoteTable.pas:line 278
at RemObjects.DataAbstract.Linq.RemoteTable`1.Execute(Expression expression) in c:\CI\b\rofx\932\Data Abstract for .NET\Source\RemObjects.DataAbstract\Linq\RemoteTable.pas:line 265
at RemObjects.DataAbstract.Linq.RemoteTableQuery`1.GetEnumerator() in c:\CI\b\rofx\932\Data Abstract for .NET\Source\RemObjects.DataAbstract\Linq\RemoteTableQuery.pas:line 74
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at admng2.ReconHistory.DoAdFind(Object sender, RoutedEventArgs e) in D:\dev\miller\admng2\ReconHistory.xaml.pas:line 652
-------------------------------------------------------------
This code has been in place for a long time. Up until this week, I had been using a custom Windows DA server service along with a client DLL. Startingi Monday, we switched this to use relativity server and a client DLL. If that helps at all…
This switch is not related to the issue. The exception happened before the request was actually sent to the server.
Just in case - did you regenerate the TableDefinitions once you did change the data source? I see that your Primary Key is defined as a nullable one (this doesn’t make sense in terms of the underlying database). I’ll log an issue to make the Schema Modeler to auto-fix such incorrect field definitions.
Possible solutions/workarounds for you are:
Wait for the next Beta build; or
(Recommended one) Mark the ReconID as Required in the Schema and regenerate the Table Definitions file