I get StackOverflowException with code like this:

internal class Program
    public const int IterationsCount = 50000;

    private static void Main(string[] args)
        var dc = new DomainConfiguration("sqlserver", "Data Source=.; Initial Catalog=DO40-Tests; Integrated Security=True;")
            UpgradeMode = DomainUpgradeMode.Recreate,


        var sw = new Stopwatch();

        using (var d = Domain.Build(dc))
            using (var s = d.OpenSession(SessionConfiguration.Default))
            using (s.Activate())
            using (var t1 = s.OpenTransaction(TransactionOpenMode.New))

                var ent = new Ent();

                for (var i = 0; i < IterationsCount; i++)
                    Session.Current.Query.All<Ent>().Where(z => z.Id == ent.Id).ToArray();

                    ent.Num = i;

                    if (i % 10 == 0)
                        Console.WriteLine($"{i}    {sw.Elapsed.TotalSeconds}");


   public class Ent : Entity
       [Field, Key]
       public Guid Id { get; set; }

       public int Num { get; set; }

Stacktrace shows that cause of StackOverflowException is recursive call of Xtensive.Tuples.DifferentialTuple.Clone() method.

Also before StackOverflow is thrown performance dramatically decrease

DO version: 5.0.13

asked Sep 05 '17 at 04:02

Gushchin%20Anton's gravatar image

Gushchin Anton

One Answer:

Hello Anton,

The problem is known but we had some difficulties in figuring out how to reproduce it. 50 000 changes and persists of the same entity is really rear case I think. How frequently do you get this error?

Anyway, we started investigation. I think the problem will be solved in next release which is about to be released actually.

Update: Fixed in 5.0.16 Beta 1

answered Sep 05 '17 at 11:53

Alexey%20Kulakov's gravatar image

Alexey Kulakov

edited Sep 28 '17 at 05:07

We also had a stackoverflow with DO5, code worked in DO4, but had a workaround which was to call Session.SaveChanges in a massive insert query, to avoid other errors. Removing Session.SaveChanges, removed the stackoverflow exception. I don't have the stack with me but I could sent it next Tuesday if needed when my colleague is back.

(Sep 06 '17 at 07:15) Benoit Nesme Benoit%20Nesme's gravatar image

Hello Benoit Nesme, if you have the same exception then no need to post it. The problem is reproduced by me successfully and we are working on it. If it is another case of StackOverflowException then create a post here on forum or write about your case to support@x-tensive.com. Thank you.

(Sep 06 '17 at 10:02) Alexey Kulakov Alexey%20Kulakov's gravatar image
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