Strange LINQ error

dataabstract
relativityserver
(Alan Olson) #1

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.

0 Likes

(Carlo Kok) #3

Hi Alan,

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.

0 Likes

(antonk) #4

Hello

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).

Thanks in advance

0 Likes

(RemObjects) #5

Thanks, logged as bugs://82263

0 Likes

(Alan Olson) #6

here is the full stack trace

  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
-------------------------------------------------------------
0 Likes

(Alan Olson) #7

here is the aprecon table

  aprecon = public partial class(System.ICloneable, System.ComponentModel.INotifyPropertyChanged, System.ComponentModel.INotifyPropertyChanging)
  private
    var m____OldValues: aprecon;
    var f____ReconID: nullable System.UInt32;
    method get__ReconID: nullable System.UInt32;
    method set__ReconID(___value___: nullable System.UInt32);
    var f____Description: System.String;
    method get__Description: System.String;
    method set__Description(___value___: System.String);
    var f____PubNumber: System.String;
    method get__PubNumber: System.String;
    method set__PubNumber(___value___: System.String);
    var f____PubName: System.String;
    method get__PubName: System.String;
    method set__PubName(___value___: System.String);
    var f____User: System.String;
    method get__User: System.String;
    method set__User(___value___: System.String);
    var f____StartDateTime: nullable System.Double;
    method get__StartDateTime: nullable System.Double;
    method set__StartDateTime(___value___: nullable System.Double);
    var f____PostDateTime: nullable System.Double;
    method get__PostDateTime: nullable System.Double;
    method set__PostDateTime(___value___: nullable System.Double);
    var f____OtherComments: System.String;
    method get__OtherComments: System.String;
    method set__OtherComments(___value___: System.String);
    var f____Filler: System.String;
    method get__Filler: System.String;
    method set__Filler(___value___: System.String);
  protected
    method OnPropertyChanged(parameterName: String);
    method OnPropertyChanging(parameterName: String);
  public
    method Clone: Object;
    event PropertyChanged: System.ComponentModel.PropertyChangedEventHandler;
    event PropertyChanging: System.ComponentModel.PropertyChangingEventHandler;
    method BeginUpdate;
    method EndUpdate(dataAdapter: RemObjects.DataAbstract.Linq.LinqDataAdapter);
    method CancelUpdate;
    [RemObjects.DataAbstract.Linq.FieldName('ReconID')]
    [RemObjects.DataAbstract.Linq.DataType(RemObjects.DataAbstract.Schema.DataType.Cardinal)]
    [RemObjects.DataAbstract.Linq.PrimaryKey]
    [RemObjects.DataAbstract.Linq.LogChanges]
    property ReconID: nullable System.UInt32 read get__ReconID write set__ReconID;
    [RemObjects.DataAbstract.Linq.FieldName('Description')]
    [RemObjects.DataAbstract.Linq.DataType(RemObjects.DataAbstract.Schema.DataType.WideString)]
    [RemObjects.DataAbstract.Linq.LogChanges]
    property Description: System.String read get__Description write set__Description;
    [RemObjects.DataAbstract.Linq.FieldName('PubNumber')]
    [RemObjects.DataAbstract.Linq.DataType(RemObjects.DataAbstract.Schema.DataType.WideString)]
    [RemObjects.DataAbstract.Linq.PrimaryKey]
    [RemObjects.DataAbstract.Linq.LogChanges]
    property PubNumber: System.String read get__PubNumber write set__PubNumber;
    [RemObjects.DataAbstract.Linq.FieldName('PubName')]
    [RemObjects.DataAbstract.Linq.DataType(RemObjects.DataAbstract.Schema.DataType.WideString)]
    [RemObjects.DataAbstract.Linq.LogChanges]
    property PubName: System.String read get__PubName write set__PubName;
    [RemObjects.DataAbstract.Linq.FieldName('User')]
    [RemObjects.DataAbstract.Linq.DataType(RemObjects.DataAbstract.Schema.DataType.WideString)]
    [RemObjects.DataAbstract.Linq.LogChanges]
    property User: System.String read get__User write set__User;
    [RemObjects.DataAbstract.Linq.FieldName('StartDateTime')]
    [RemObjects.DataAbstract.Linq.DataType(RemObjects.DataAbstract.Schema.DataType.Float)]
    [RemObjects.DataAbstract.Linq.LogChanges]
    property StartDateTime: nullable System.Double read get__StartDateTime write set__StartDateTime;
    [RemObjects.DataAbstract.Linq.FieldName('PostDateTime')]
    [RemObjects.DataAbstract.Linq.DataType(RemObjects.DataAbstract.Schema.DataType.Float)]
    [RemObjects.DataAbstract.Linq.LogChanges]
    property PostDateTime: nullable System.Double read get__PostDateTime write set__PostDateTime;
    [RemObjects.DataAbstract.Linq.FieldName('OtherComments')]
    [RemObjects.DataAbstract.Linq.DataType(RemObjects.DataAbstract.Schema.DataType.WideString)]
    [RemObjects.DataAbstract.Linq.LogChanges]
    property OtherComments: System.String read get__OtherComments write set__OtherComments;
    [RemObjects.DataAbstract.Linq.FieldName('Filler')]
    [RemObjects.DataAbstract.Linq.DataType(RemObjects.DataAbstract.Schema.DataType.WideString)]
    [RemObjects.DataAbstract.Linq.LogChanges]
    property Filler: System.String read get__Filler write set__Filler;
  end;
0 Likes

(Alan Olson) #8

Checkres is a List of nullable UInt32 values

0 Likes

(Alan Olson) #9

One other point of curiosity…

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…

0 Likes

(RemObjects) #10

bugs://82263 got closed with status fixed.

0 Likes

(antonk) #11

Thanks for the info

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
0 Likes

(RemObjects) #12

Thanks, logged as bugs://82267

0 Likes

(RemObjects) #13

bugs://82267 got closed with status fixed.

0 Likes