开发者

NHibernate 3.1 NHibernate.Linq.NhRelinqQueryParser exception "Sequence contains more than one matching element"

开发者 https://www.devze.com 2023-03-05 12:35 出处:网络
I\'m using Nhibernate 3.1 / FluentNhibernate 1.2 When I work in release mode with CTRL + F5, I don\'t get any exception.

I'm using Nhibernate 3.1 / FluentNhibernate 1.2

When I work in release mode with CTRL + F5, I don't get any exception. But in debug mode with F5 following exception occurs:

A console application, for this code :

_Session.Query<Foo> ().Where (x=>x.Bar == "bar").FirstOrDefault()

Exception:

System.TypeInitializationException was unhandled
  Message=The type initializer for 'NHibernate.Linq.NhRelinqQueryParser' threw an exception.
  Source=NHibernate
  TypeName=NHibernate.Linq.NhRe开发者_Go百科linqQueryParser
  StackTrace:
       at NHibernate.Linq.NhRelinqQueryParser.Parse(Expression expression)
       at NHibernate.Linq.NhLinqExpression.Translate(ISessionFactoryImplementor sessionFactory) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Linq\NhLinqExpression.cs:line 65
       at NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(String queryIdentifier, IQueryExpression queryExpression, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Hql\Ast\ANTLR\ASTQueryTranslatorFactory.cs:line 27
       at NHibernate.Engine.Query.HQLExpressionQueryPlan.CreateTranslators(String expressionStr, IQueryExpression queryExpression, String collectionRole, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Engine\Query\HQLExpressionQueryPlan.cs:line 34
       at NHibernate.Engine.Query.HQLExpressionQueryPlan..ctor(String expressionStr, IQueryExpression queryExpression, String collectionRole, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Engine\Query\HQLExpressionQueryPlan.cs:line 23
       at NHibernate.Engine.Query.HQLExpressionQueryPlan..ctor(String expressionStr, IQueryExpression queryExpression, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Engine\Query\HQLExpressionQueryPlan.cs:line 21
       at NHibernate.Engine.Query.QueryPlanCache.GetHQLQueryPlan(IQueryExpression queryExpression, Boolean shallow, IDictionary`2 enabledFilters) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Engine\Query\QueryPlanCache.cs:line 88
       at NHibernate.Impl.AbstractSessionImpl.GetHQLQueryPlan(IQueryExpression queryExpression, Boolean shallow) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl\AbstractSessionImpl.cs:line 312
       at NHibernate.Impl.AbstractSessionImpl.CreateQuery(IQueryExpression queryExpression) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl\AbstractSessionImpl.cs:line 268
       at NHibernate.Linq.NhQueryProvider.PrepareQuery(Expression expression, IQuery& query, NhLinqExpression& nhQuery) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Linq\NhQueryProvider.cs:line 43
       at NHibernate.Linq.NhQueryProvider.Execute(Expression expression) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Linq\NhQueryProvider.cs:line 26
       at NHibernate.Linq.NhQueryProvider.Execute[TResult](Expression expression) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Linq\NhQueryProvider.cs:line 103
       at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source)
       at x.Persistence.NH.NHibernateUnitOfWork.<>c__DisplayClass11`1.<FindOne>b__10() in D:\x\x\x.Persistence.NH\NHibernateUnitOfWork.cs:line 71
       at x.Persistence.NH.NHibernateUnitOfWork.Transactional[TResult](Func`1 func) in D:\x\x\x.Persistence.NH\NHibernateUnitOfWork.cs:line 88
       at x.Persistence.NH.NHibernateUnitOfWork.FindOne[T](Expression`1 predicate) in D:\x\x\x.Persistence.NH\NHibernateUnitOfWork.cs:line 71
       at Sample.Sam.Start() in D:\x\x\Sample\Sam.cs:line 28
       at Sample.Sam.Main() in D:\x\x\Sample\Sam.cs:line 16
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.InvalidOperationException
       Message=Sequence contains more than one matching element
       Source=System.Core
       StackTrace:
            at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source, Func`2 predicate)
            at Remotion.Data.Linq.Parsing.ExpressionTreeVisitors.Transformation.ExpressionTransformerRegistry.CreateDefault() in :line 0
            at NHibernate.Linq.NhRelinqQueryParser..cctor() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Linq\NhRelinqQueryParser.cs:line 26
       InnerException: 


in my team we have the same error using the same versions of nHibernate and fluentnhibernate, anyway that error appears only on one machine (out of 8). It seems a problem inherent the debug of visual studio, the same project run fine if started outside visual studio or if the debug process is done through attaching the process from the Debug menu. I'll investigate on this as soon as possible, but at this moment the debug from this pc is done indirectly as depicted above. Also, this request http://www.mail-archive.com/nhusers@googlegroups.com/msg25959.html seems interesting.


One of the team member had this issue only when he debugged with VSDEV.

After we turning off IntelliTrace fixed this issue.


I wrestled with this issue too for a couple of days trying to figure out why in the world I was the only one in my team getting that error.

I am not exactly sure of all the paths that I took, however, in my case it turned out to be a privileges error, even though my domain login was an admin on the local box, and I was running everything on full trust, and UAC was off.

The trick that did it for me was to completely delete my windows profile and recreate it again. I have no idea what in the profile was causing the issue, but it worked for me.

Hope this helps

-Diego


Check your intellitrace settings!

For me, it works when IntelliTrace events only is selected. When I have IntelliTrace events and call information selected, I get the nhibernate bug.


I had this same issue, it happens only when I try to use the NHibernate.Linq library. (I'm using NHibernate 3.1, and NHibernate.Linq 1.0). I didn't want to lose the ability to debug my application in Visual Studio, so I converted the NHibernate.Linq calls to the NHibernate QueryOver API instead, which is similar to Linq but doesn't actually use it.

So for your code example, you could change this:

_Session.Query<Foo>().Where(x => x.Bar == "bar").FirstOrDefault();

To use QueryOver instead:

_Session.QueryOver<Foo>().Where(x => x.Bar == "bar").List().FirstOrDefault();

If you do that, you should be able to debug in Visual Studio now, without getting the same exception (at least I did).

0

精彩评论

暂无评论...
验证码 换一张
取 消