# Strange LINQ error

**URL:** https://talk.remobjects.com/t/strange-linq-error/19092
**Category:** Data Abstract
**Tags:** relativityserver, dataabstract
**Created:** [April 3, 2019, 2:00pm UTC](https://talk.remobjects.com/t/strange-linq-error/19092 "2019-04-03T14:00:53Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![aolson](https://talk.remobjects.com/user_avatar/talk.remobjects.com/aolson/32/11707_2.png) [@aolson](https://talk.remobjects.com/u/aolson)
#### Post date: [April 3, 2019, 2:00pm UTC](https://talk.remobjects.com/t/strange-linq-error/19092/1 "2019-04-03T14:00:53Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![ck](https://talk.remobjects.com/user_avatar/talk.remobjects.com/ck/32/8740_2.png) [@ck](https://talk.remobjects.com/u/ck)
#### Post date: [April 4, 2019, 5:10am UTC](https://talk.remobjects.com/t/strange-linq-error/19092/3 "2019-04-04T05:10:59Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![antonk](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/a/a5b964/32.png) [@antonk](https://talk.remobjects.com/u/antonk)
#### Post date: [April 4, 2019, 8:18am UTC](https://talk.remobjects.com/t/strange-linq-error/19092/4 "2019-04-04T08:18:10Z")

</div>

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

---

<div class="post-metadata">

### Author: ![RemObjectsSoftware](https://talk.remobjects.com/user_avatar/talk.remobjects.com/remobjectssoftware/32/15947_2.png) [@RemObjectsSoftware](https://talk.remobjects.com/u/RemObjectsSoftware)
#### Post date: [April 4, 2019, 9:38am UTC](https://talk.remobjects.com/t/strange-linq-error/19092/5 "2019-04-04T09:38:27Z")

</div>

Thanks, logged as bugs://82263

---

<div class="post-metadata">

### Author: ![aolson](https://talk.remobjects.com/user_avatar/talk.remobjects.com/aolson/32/11707_2.png) [@aolson](https://talk.remobjects.com/u/aolson)
#### Post date: [April 4, 2019, 12:06pm UTC](https://talk.remobjects.com/t/strange-linq-error/19092/6 "2019-04-04T12:06:49Z")

</div>

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
-------------------------------------------------------------
```

---

<div class="post-metadata">

### Author: ![aolson](https://talk.remobjects.com/user_avatar/talk.remobjects.com/aolson/32/11707_2.png) [@aolson](https://talk.remobjects.com/u/aolson)
#### Post date: [April 4, 2019, 12:08pm UTC](https://talk.remobjects.com/t/strange-linq-error/19092/7 "2019-04-04T12:08:43Z")

</div>

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;
```

---

<div class="post-metadata">

### Author: ![aolson](https://talk.remobjects.com/user_avatar/talk.remobjects.com/aolson/32/11707_2.png) [@aolson](https://talk.remobjects.com/u/aolson)
#### Post date: [April 4, 2019, 12:09pm UTC](https://talk.remobjects.com/t/strange-linq-error/19092/8 "2019-04-04T12:09:05Z")

</div>

Checkres is a List of nullable UInt32 values

---

<div class="post-metadata">

### Author: ![aolson](https://talk.remobjects.com/user_avatar/talk.remobjects.com/aolson/32/11707_2.png) [@aolson](https://talk.remobjects.com/u/aolson)
#### Post date: [April 4, 2019, 12:10pm UTC](https://talk.remobjects.com/t/strange-linq-error/19092/9 "2019-04-04T12:10:34Z")

</div>

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…

---

<div class="post-metadata">

### Author: ![RemObjectsSoftware](https://talk.remobjects.com/user_avatar/talk.remobjects.com/remobjectssoftware/32/15947_2.png) [@RemObjectsSoftware](https://talk.remobjects.com/u/RemObjectsSoftware)
#### Post date: [April 4, 2019, 2:06pm UTC](https://talk.remobjects.com/t/strange-linq-error/19092/10 "2019-04-04T14:06:01Z")

</div>

bugs://82263 got closed with status fixed.

---

<div class="post-metadata">

### Author: ![antonk](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/a/a5b964/32.png) [@antonk](https://talk.remobjects.com/u/antonk)
#### Post date: [April 4, 2019, 2:10pm UTC](https://talk.remobjects.com/t/strange-linq-error/19092/11 "2019-04-04T14:10:25Z")

</div>

Thanks for the info

> [@aolson](#):
>
> 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

---

<div class="post-metadata">

### Author: ![RemObjectsSoftware](https://talk.remobjects.com/user_avatar/talk.remobjects.com/remobjectssoftware/32/15947_2.png) [@RemObjectsSoftware](https://talk.remobjects.com/u/RemObjectsSoftware)
#### Post date: [April 4, 2019, 2:10pm UTC](https://talk.remobjects.com/t/strange-linq-error/19092/12 "2019-04-04T14:10:28Z")

</div>

Thanks, logged as bugs://82267

---

<div class="post-metadata">

### Author: ![RemObjectsSoftware](https://talk.remobjects.com/user_avatar/talk.remobjects.com/remobjectssoftware/32/15947_2.png) [@RemObjectsSoftware](https://talk.remobjects.com/u/RemObjectsSoftware)
#### Post date: [April 5, 2019, 10:28am UTC](https://talk.remobjects.com/t/strange-linq-error/19092/13 "2019-04-05T10:28:50Z")

</div>

bugs://82267 got closed with status fixed.
