Insert into multiple tables = FileNotFoundException (Could not load file or assembly mscorlib.XmlSerializers)

Oct 30, 2016 at 4:58 AM
Edited Oct 30, 2016 at 5:06 AM
What is wrong with how I am writing to 2 tables in the same transaction? I tried to follow the example in the documentation, (which throws the same exception by the way). I have tried with a Commit after each Insert, but get the same results.
public static void TEST()
{
    var oRandom = new Random();

    var oDBreezeEngine = new DBreezeEngine("TEST");

    using (var oTransaction = oDBreezeEngine.GetTransaction())
    {
        for (var i = 0; i < 100; i++)
        {
            oTransaction.Insert<string, DateTime>(
                (oRandom.Next() % 2 == 0) ? "A" : "B",
                Guid.NewGuid().ToString(),
                DateTime.Now);
            //oTransaction.Commit();
        }

        /*
        oTransaction.Commit() throws the following exception at 
        .\DBreeze-master\DBreeze\Utils\XmlSerializator.cs line 28 in method SerializeXml.

        Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.dll

        Additional information: Could not load file or assembly 'mscorlib.XmlSerializers, Version=4.0.0.0, 
        Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot 
        find the file specified.
        */

        oTransaction.Commit();
    }
}
Example from documentation:
//You can modify more then one table inside of the transaction.
using (var tran = engine.GetTransaction())
{
    tran.Insert<int, int>("t1", 1, 1);
    tran.Insert<uint, string>("t2", 1, "hello");
    tran.Commit();
    //or
    //tran.Rollback();
    tran.Insert<int, int>("t1", 2, 1);
    tran.Insert<uint, string>("t2", 2, "world");
    tran.Commit();
}
Thank you!
Coordinator
Nov 16, 2016 at 8:10 AM
I think the biggest problem is the way how you initialize DBreezeEngine... supplying instead of folder name, just "TEST"...
Commit better to make in the end of transaction.
DBreezeEngine eng = null;

        private void button1_Click(object sender, EventArgs e)
        {            
            if (eng == null)
                eng = new DBreezeEngine(@"D:\temp\DBR1");

            Random oRandom = new Random();

            using (var oTransaction = eng.GetTransaction())
            {
                for (var i = 0; i < 100; i++)
                {
                    oTransaction.Insert<string, DateTime>(
                        (oRandom.Next() % 2 == 0) ? "A" : "B",
                        Guid.NewGuid().ToString(),
                        DateTime.Now);                    
                }

                oTransaction.Commit();
            }
        }