Since we have migrated our solutions from VS2010 to VS2017 a lambda expression of NHibernate QueryOver is not working properly. After various tests I've found that removing a JoinAlias (but removing explicitly from code it's independent if it's executed or not), the code works fine.
After debugging NHibernate (3.3.3SP1) I have found that the difference was on the alias of the join (an expression) that in bad case it's detected as MemberAccess, and the correspondent string is strange.
I'll try to show the relevant parts of my code but testing it alone works fine:
LiquidacionDao.cs
Poliza aliasJoinCia = null;
this.Session.QueryOver<Recibo>(() => recibo)
.Inner.JoinQueryOver<Poliza>(r => r.Poliza, () => aliasJoinCia);
...
...
...
// If I remove those lines, the code works
GestorDeCobro aliasJoinGestoresCobro = null;
queryOver.Inner.JoinAlias(r => r.GestorDeCobro, () => aliasJoinGestoresCobro);
...
...
return queryOver.List();
Debugging JoinQueryOver and JoinAlias, I have seen that when it works (without the last lines) the debugger shows the following string on watch:
{() => value(mpm.seg.Dao.Recibos.Liquidaciones.LiquidacionDao+<>c__DisplayClass33_0).aliasJoinCia}
and the property "DebugView":
.Constant<mpm.seg.Dao.Recibos.Liquidaciones.LiquidacionDao+<>c__DisplayClass6_0>(mpm.seg.Dao.Recibos.Liquidaciones.LiquidacionDao+<>c__DisplayClass6_0).aliasJoinCia
And when it fails the watch shows the following string:
{() => value(mpm.seg.Dao.Recibos.Liquidaciones.LiquidacionDao+<>c__DisplayClass33_3).CS$<>8__locals1.aliasJoinCia}
and the property "DebugView":
.Lambda #Lambda1<System.Func`1[mpm.seg.ServiceModel.DataContracts.Polizas.Poliza]>() {
(.Constant<mpm.seg.Dao.Recibos.Liquidaciones.LiquidacionDao+<>c__DisplayClass34_3>(mpm.seg.Dao.Recibos.Liquidaciones.LiquidacionDao+<>c__DisplayClass34_3).CS$<>8__locals1).aliasJoinCia
}
I cannot understand why the expression is interpreted different in some cases, and only in Visual Studio 2017, if I open the code on Visual Studio 2010 works always fine.
It's time to upgrade.
The introduction of Roslyn compiler in Visual Studio 2015 brought a slight change how the closures in expression trees are generated. Unfortunately this change was unforeseen in NHibernate (it's really hard to predict such changes).
This has been fixed in 3.3.5/3.4.1/4.0.4 (Issue: NH-3795).
Version 3.3.5 has only 2 bugs fixed on top of version you are using, so it should be extremely safe to upgrade.