Could not resolve property: CS$<>8__locals2 of: BusinessObjectMain; Nhibernate QueryOver Linq, lambda expression inside a for loop

We use Vs2019 with an older version of Nhibernate 3.2.
We recently upgraded to VS2019. This code worked correctly in VS2010.
We are getting this error with Nibernate QueryOver, lambda expressions inside a where clause. I stripped it down to a minimal version. During runtime Block 1 fails and Block 2 does not. Why? I can’t figure this out.
Could it be something related to .net framework 4.8, roselyn or an older version of Nhibernate?
I didn’t post all the Business Objects here but if needed I can do so. I am also seeing this behavior across the application for different Business Objects.

could not resolve property: CS$<>8__locals2 of: BusinessObjectMain

Block 1

var EventQuery = session.QueryOver<BusinessObjectMain()
                    .JoinAlias(ce => ce.Bo1, () => Bo1)
                    .JoinAlias(ce => ce.Bo2, () => Bo2, JoinType.LeftOuterJoin)
                    .JoinAlias(() => Bo2.Bo3, () =>Bo3, JoinType.LeftOuterJoin)
                    ;



for (int i = 0; i < 1; i++) {

  object[] arr = new object[1];
  arr[0] = 202;
  EventQuery = EventQuery.Where(() => Bo3.TypeId.IsIn(arr));
}


var Results = EventQuery.Future<Data>();
 var list = Results.ToList();---Error happens here.  could not resolve property: CS$<>8__locals2 of: BusinessObjectMain

Why does the code below work? If I move the Where clause outside the for loop, it works correctly without any errors

Block 2

 var EventQuery = session.QueryOver<BusinessObjectMain()
                        .JoinAlias(ce => ce.Bo1, () => Bo1)
                        .JoinAlias(ce => ce.Bo2, () => Bo2, JoinType.LeftOuterJoin)
                        .JoinAlias(() => Bo2.Bo3, () =>Bo3, JoinType.LeftOuterJoin)
                        ;
    
      object[] arr = new object[1];
      arr[0] = 202;
      EventQuery = EventQuery.Where(() => Bo3.TypeId.IsIn(arr));
    
    for (int i = 0; i < 1; i++) {
    
     
    }
    
    
    var Results = EventQuery.Future<Data>();
     var list = Results.ToList()

NHibernate is not part of this community. It has a separate community. I think you can ask questions here: https://groups.google.com/g/nhusers

There is also more information on the official website: https://nhibernate.info/