魔术字符串在nHibernate Profiler中导致错误

时间:2012-12-03 20:04:12

标签: nhibernate fluent-nhibernate nhibernate-profiler

我有一个业务应用程序,我负责维护,这个间歇性的错误不断出现在其中创建新的评论。我终于得到了一个引起它的精确字符串,在慢慢缩小文本段落到导致它的确切部分之后,我把它缩小了最基本的组件。但我无法解决它在各地应用创可贴的问题。我想知道这是否是一个常见问题,并且可能会得到一些反馈。

我正在使用Fluent nHibernate(1.3.0.773)和nHibernate(3.3.1.400),我也删除了我的映射文件,所以请确保它不是因为我可以得到它并且仍然可以重现错误(并具有正常运行的构建)。这是使用FluentMappings.ExportTo()转储配置时产生的注释内容。

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class xmlns="urn:nhibernate-mapping-2.2" name="Core.Comment, Core, Version=5.0.4720.19853, Culture=neutral, PublicKeyToken=null" table="tblComments">
    <id name="CommentId" type="System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <column name="CommentId" />
      <generator class="guid.comb" />
    </id>
    <property name="OwnerId" type="System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <column name="OwnerId" />
    </property>
    <property name="Text" type="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <column name="Description" />
    </property>
  </class>
</hibernate-mapping>

非常简单,但是如果正在提交的文本中有一个撇号,那么单词update后跟一个右括号,当我尝试提交事务时,我收到ArgumentOutOfRangeException错误。

以下字符串会导致问题

  • Lorem ipsum dolor坐下来,念念。 (这不会更新)
  • 不会更新)
  • '更新)

这些不会导致问题

  • Lorem ipsum dolor坐下来,念念。 (这确实更新了)
  • 更新)
  • '更新
  • 'updat)

你能给出的任何见解都会很棒。

更新 我应该提一下,当我连接nHibernate Profiler时,没有与插入新记录相关的SQL生成。所以我假设它来自nHibernate内部的某种逻辑?

堆栈跟踪

[ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index]
   System.ThrowHelper.ThrowArgumentOutOfRangeException() +72
   System.Collections.Generic.List`1.get_Item(Int32 index) +34
   NHibernate.AdoNet.Util.FormatProcess.CloseParen() +141
   NHibernate.AdoNet.Util.FormatProcess.Perform() +452
   NHibernate.AdoNet.Util.BasicFormatter.Format(String source) +67
   NHibernate.AdoNet.SqlClientBatchingBatcher.AddToBatch(IExpectation expectation) +310
   NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Boolean[] notNull, Int32 j, SqlCommandInfo sql, Object obj, ISessionImplementor session) +914
   NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Object obj, ISessionImplementor session) +341
   NHibernate.Action.EntityInsertAction.Execute() +371
   NHibernate.Engine.ActionQueue.Execute(IExecutable executable) +48
   NHibernate.Engine.ActionQueue.ExecuteActions(IList list) +128
   NHibernate.Engine.ActionQueue.ExecuteActions() +35
   NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource session) +156
   NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent event) +180
   NHibernate.Impl.SessionImpl.Flush() +295
   NHibernate.Transaction.AdoTransaction.Commit() +189
   Web.Filters.NHibernateActionFilter.OnActionExecuted(ActionExecutedContext filterContext) in c:\Development\[Project Folder]\Web.Controllers\Filters\NHibernateActionFilter.cs:82
   System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +354
   System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +323
   System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +323
   System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeActionMethodWithFilters>b__36(IAsyncResult asyncResult) +44
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +139
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +102
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +74
   System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +68
   System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +184
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +136
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +66
   System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +40
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +47
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +151
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +68
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +47
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +151
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +65
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +39
   System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +45
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +47
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +151
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +66
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9629708
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

1 个答案:

答案 0 :(得分:0)

好的,所以我发现了导致它的原因。一旦我从项目中删除了nHibernate Profiler的初始化,错误就停止了。它必须在执行之前尝试格式化字符串以进行日志记录 - 并且因为它已经爆炸,所以它永远不会实际执行查询。对我来说错误,日志记录应该吞下错误,或者至少不要让它干扰正常操作。

更新:使用nHibernate Profiler 2时会出现同样的问题,但只要我注释掉NHibernateProfiler.Initialize(),问题就会消失。去看看我是否可以得到开发人员的一些支持。请注意,您实际上不必使用nHibernate Profiler附加您的进程,只需初始化探查器就足以导致问题。我试图在12月5日通过电子邮件联系nHibernate Profiler支持,但还没有收到任何回复,所以我不知道是否已经查看过。