I have a web service and I'm experiencing a strange exception:

System.InvalidOperationException: Unable to change command: it is already prepared
   at Xtensive.Orm.Providers.Command.AddPart(CommandPart part)
   at Xtensive.Orm.Providers.BatchingCommandProcessor.Xtensive.Orm.Providers.ISqlTaskProcessor.ProcessTask(SqlLoadTask task)
   at Xtensive.Orm.Providers.BatchingCommandProcessor.ExecuteBatch(Int32 numberOfTasks, QueryRequest lastRequest)
   at Xtensive.Orm.Providers.SqlSessionHandler.ExecuteQueryTasks(IEnumerable`1 queryTasks, Boolean allowPartialExecution)
   at Xtensive.Orm.Session.ProcessDelayedQueries(Boolean allowPartialExecution)
   at Xtensive.Orm.Internals.Prefetch.Fetcher.ExecuteTasks(IEnumerable`1 containers, Boolean skipPersist)
   at Xtensive.Orm.Internals.Prefetch.PrefetchManager.ExecuteTasks(Boolean skipPersist)
   at Xtensive.Orm.Providers.SqlSessionHandler.FetchEntityState(Key key)
   at Xtensive.Orm.QueryEndpoint.SingleOrDefault(Key key)
   at Xtensive.Orm.Internals.FieldAccessors.EntityFieldAccessor`1.GetValue(Persistent obj)
   at Xtensive.Orm.Persistent.GetFieldValue[T](FieldInfo field)
   at Quadra.WMS.BusinessLogic.Place.get_FullName()
   at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
   at System.String.Join(String separator, IEnumerable`1 values)
   at Quadra.WMS.BusinessLogic.Connector1C.DoUpdateAddress(Int32 skuId, IEnumerable`1 places)

Quadra.WMS.BusinessLogic.Place.get_FullName is in this code:

public class Place : Entity
    public Place(Session session) : base(session)

    public int Id { get; set; }

    public string Name { get; set; }

    public Barcode Barcode { get; set; }

    public Place ParentPlace { get; set; }

    public string FullName
            var placeList = new List<string>();
            var p = this;
            while (p != null)
                p = p.ParentPlace;
            return string.Join(" / ", Enumerable.Reverse(placeList));

FullName should return a string of a full path of the place and its parent places. I'm using 5.0-beta1 version.

asked Sep 04 '14 at 04:02

Pavel%20Kudinov's gravatar image

Pavel Kudinov

edited Sep 04 '14 at 04:48

Hi Pavel. I think problem is not in FullName. I created model with your type and filled it. Then i created query and for each entity of result i got FullName value and everything was fine. You have some delayed query. Could you show me more code, what do you do when this exception throws? Because I can't reproduce situation based on this data

(Sep 05 '14 at 01:05) Alexey Kulakov Alexey%20Kulakov's gravatar image

This is a phantom problem. If I make lots of retries via F5 in my browser, this code works fine in 1 try of about 6. It seemes that there is a concurrency or something. I also cannot reproduce it anywhere in tests just in production env. What I'm doing is I'm running this code in another thread using Task.Factory.StartNew(() => myFunc(place.FullName))

(Sep 06 '14 at 04:04) Pavel Kudinov Pavel%20Kudinov's gravatar image

After I stopped doing it in another thread I don't get this exception, I get another one:

System.NullReferenceException: Object reference not set to an instance of an object. at Xtensive.Orm.Providers.Command.NextRow()

(Sep 07 '14 at 04:47) Pavel Kudinov Pavel%20Kudinov's gravatar image

One Answer:

It looks like threading was a problem. After I removed it and started making task synchronously, everything went fine. So this question is fixed, I will open another one if I find a reproduceble problem

answered Sep 16 '14 at 05:13

Pavel%20Kudinov's gravatar image

Pavel Kudinov

Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA