-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: 'Code supposed to be unreachable' with linq
PostPosted: Wed Mar 30, 2011 3:07 am 
Newbie

Joined: Wed Mar 30, 2011 2:59 am
Posts: 1
Hi,

I've posted this question on the msdn forums, where I got redirected here. I'll resume it here.

Post 1:
I've got an exception with the message 'System.InvalidOperationException: Code supposed to be unreachable' originating from System.Core when performing underneath code
Code:
public ushort RemoveProvider(ulong providerId)
{
  //make sure the provider isn't referenced by any device
  var refDevices = (from device in DataContext.Linq<Device>()
               where device.Active && device.Providers.Select(x => x.ID).Contains(providerId)
               select device).ToList();
  ....
}

DataContext.Linq<Device>() returns a list of devices by using a NHibernate data context which is working. Each device contains 0-n providers.
refDevices should contain a list of devices where the device contains tzhe provider with the id providerId or be empty if the providerId isn't referenced anymore.

Here's the full stack trace
Code:
at System.Linq.Expressions.Compiler.StackSpiller.RewriteExpression(Expression node, Stack stack)
  at System.Linq.Expressions.Compiler.StackSpiller.ChildRewriter.Add(Expression node)
  at System.Linq.Expressions.Compiler.StackSpiller.ChildRewriter.AddArguments(IArgumentProvider expressions)
  at System.Linq.Expressions.Compiler.StackSpiller.RewriteMethodCallExpression(Expression expr, Stack stack)
  at System.Linq.Expressions.Compiler.StackSpiller.RewriteExpression(Expression node, Stack stack)
  at System.Linq.Expressions.Compiler.StackSpiller.RewriteExpressionFreeTemps(Expression expression, Stack stack)
  at System.Linq.Expressions.Compiler.StackSpiller.Rewrite[T](Expression`1 lambda)
  at System.Linq.Expressions.Expression`1.Accept(StackSpiller spiller)
  at System.Linq.Expressions.Compiler.LambdaCompiler.Compile(LambdaExpression lambda, DebugInfoGenerator debugInfoGenerator)
  at System.Linq.Expressions.LambdaExpression.Compile()
  at NHibernate.Linq.Util.QueryUtil.GetExpressionValue(Expression expression)
  at NHibernate.Linq.Visitors.WhereArgumentsVisitor.GetCollectionContainsCriteria(Expression list, Expression containedExpr)
  at NHibernate.Linq.Visitors.WhereArgumentsVisitor.VisitMethodCall(MethodCallExpression expr)
  at NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp)
  at NHibernate.Linq.Visitors.NHibernateExpressionVisitor.Visit(Expression exp)
  at NHibernate.Linq.Visitors.WhereArgumentsVisitor.VisitAndAlsoExpression(BinaryExpression expr)
  at NHibernate.Linq.Visitors.WhereArgumentsVisitor.VisitBinary(BinaryExpression expr)
  at NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp)
  at NHibernate.Linq.Visitors.NHibernateExpressionVisitor.Visit(Expression exp)
  at NHibernate.Linq.Visitors.ExpressionVisitor.VisitLambda(LambdaExpression lambda)
  at NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp)
  at NHibernate.Linq.Visitors.NHibernateExpressionVisitor.Visit(Expression exp)
  at NHibernate.Linq.Visitors.WhereArgumentsVisitor.VisitUnary(UnaryExpression expr)
  at NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp)
  at NHibernate.Linq.Visitors.NHibernateExpressionVisitor.Visit(Expression exp)
  at NHibernate.Linq.Visitors.WhereArgumentsVisitor.GetCriterion(ICriteria rootCriteria, ISession session, Expression expression)
  at NHibernate.Linq.Visitors.RootVisitor.HandleWhereCall(MethodCallExpression call)
  at NHibernate.Linq.Visitors.RootVisitor.VisitMethodCall(MethodCallExpression expr)
  at NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp)
  at NHibernate.Linq.Visitors.NHibernateExpressionVisitor.Visit(Expression exp)
  at NHibernate.Linq.Visitors.NHibernateQueryTranslator.TranslateInternal(Expression expression)
  at NHibernate.Linq.Visitors.NHibernateQueryTranslator.Translate(Expression expression, QueryOptions queryOptions)
  at NHibernate.Linq.NHibernateQueryProvider.TranslateExpression(Expression expression)
  at NHibernate.Linq.NHibernateQueryProvider.Execute(Expression expression)
  at NHibernate.Linq.Query`1.GetEnumerator()
  at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
  at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
  at Telecontrol.SIPPR.Server.Business.Services.ConfigurationService.RemoveProvider(UInt64 providerId) in D:\dev\telecontrol\Telecontrol.SIPPR.Server\Telecontrol.SIPPR.Server.Business.Services\ConfigurationService.cs:line 477
  at Telecontrol.SIPPR.Server.Communication.ServiceImplementation.ProdSw.ConfigurationWS.<>c__DisplayClassa.<RemoveProvider>b__9() in D:\dev\telecontrol\Telecontrol.SIPPR.Server\Telecontrol.SIPPR.Server.Communication.ServiceImplementation.ProdSw\ConfigurationWS.cs:line 47
  at Telecontrol.SIPPR.Server.Communication.ServiceImplementation.Notification.WCFServiceBase.<>c__DisplayClassa`1.<Execute>b__8() in D:\dev\telecontrol\Telecontrol.SIPPR.Server\Telecontrol.SIPPR.Server.Communication.ServiceImplementation.Notification\WCFServiceBase.cs:line 260
  at Telecontrol.SIPPR.Server.Communication.ServiceImplementation.Notification.WCFServiceBase.ExecuteInExceptionScope(Action action) in D:\dev\telecontrol\Telecontrol.SIPPR.Server\Telecontrol.SIPPR.Server.Communication.ServiceImplementation.Notification\WCFServiceBase.cs:line 125


Post 2:
If executing underbeath code, everything works fine (notice the toList())
Code:
var refDevices = (from device in DataContext.Linq<Device>().ToList()
              where device.Active && device.Providers.Select(x => x.ID).Contains(providerId)
              select device).ToList();

This means, the sql query can't be generated by linq. If performing the filtering (where...) on the list already retrieved from the db, it works. Unfortunately, we can't use this because all the existing devices have to be retrieved from the db first.

I've got a working solution (for now) using hql:
Code:
string sqlQuery = "select COUNT(Device_id)" +
                " from providerstodevices" +
                " left join device on providerstodevices.Device_id = device.ID" +
                string.Format(" where providerstodevices.Provider_id = {0} AND device.Active = 1", providerId);
      var session = DataContext.NHibernateSession;
      var queryPurge = session.CreateSQLQuery(sqlQuery);
      long nbLinks = (long)queryPurge.UniqueResult();

I'd expect getting another error then 'System.InvalidOperationException: Code supposed to be unreachable' though ;)

As the message source for the exception was System.Core, at first I didn't think it was a NHibernate problem. Anyone can clarify the situation for me?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.