System.Exception from Getting Started code

Mar 16, 2015 at 11:05 PM
Edited Mar 16, 2015 at 11:07 PM
I tried the code from the 'Getting Started' section, but unfortunately received a System.Exception when calling 'rdb.RegisterView(new SalesInvoiceView());'.

This is the code I tried:
namespace ConsoleApplication
{
    using System;
    using System.Collections.Generic;
    using RaptorDB;

    static class Program
    {
        static RaptorDB rdb; // 1 instance

        static void Main(string[] args)
        {
            rdb = RaptorDB.Open("data"); // a "data" folder beside the executable
            Global.RequirePrimaryView = false;

            Console.WriteLine("Registering views..");
            rdb.RegisterView(new SalesInvoiceView());

            DoWork();

            Console.WriteLine("press any key...");
            Console.ReadKey();
            Console.WriteLine("\r\nShutting down...");
            rdb.Shutdown(); // explicit shutdown
        }

        static void DoWork()
        {
            long c = rdb.DocumentCount();
            if( c > 0 ) // not the first time running
            {
                var result = rdb.Query<SalesInvoiceViewRowSchema>(x => x.Serial < 100);
                // show the rows
                Console.WriteLine(fastJSON.JSON.ToNiceJSON(result.Rows, new fastJSON.JSONParameters { UseExtensions = false, UseFastGuid = false }));
                // show the count
                Console.WriteLine("Query result count = " + result.Count);
                return;
            }

            Console.Write("Inserting 100,000 documents...");
            int count = 100000;

            for( int i = 0; i < count; i++ )
            {
                var inv = CreateInvoice(i);

                // save here
                rdb.Save(inv.ID, inv);
            }

            Console.WriteLine("done.");
        }

        static SalesInvoice CreateInvoice(int counter)
        {
            // new invoice
            var inv = new SalesInvoice()
            {
                Date = DateTime.Now,
                Serial = counter % 10000,
                CustomerName = "Name",
                NoCase = "Me " + counter % 10,
                Status = (byte)(counter % 4),
                Address = "Street",
                Approved = counter % 100 == 0 ? true : false
            };
            // new line items
            inv.Items = new List<LineItem>();
            for( int k = 0; k < 5; k++ )
                inv.Items.Add(new LineItem() { Product = "prod " + k, Discount = 0, Price = 10 + k, QTY = 1 + k });

            return inv;
        }

        public class SalesInvoiceViewRowSchema : RDBSchema
        {
            public string CustomerName;
            public string NoCase;
            public DateTime Date;
            public string Address;
            public int Serial;
        }

        [RegisterView]
        public class SalesInvoiceView : View<SalesInvoice>
        {
            public SalesInvoiceView()
            {
                this.Name = "SalesInvoice";
                this.Description = "A primary view for SalesInvoices";
                this.isPrimaryList = true;
                this.isActive = true;
                this.BackgroundIndexing = true;
                this.Version = 1;

                this.Schema = typeof(SalesInvoiceViewRowSchema);

                this.Mapper = (api, docid, doc) =>
                {
                    api.EmitObject(docid, doc);
                };
            }
        }
    }

    internal class SalesInvoice
    {
        public Guid ID { get; set; }
        public DateTime Date { get; set; }
        public int Serial { get; set; }
        public string CustomerName { get; set; }
        public string NoCase { get; set; }
        public byte Status { get; set; }
        public string Address { get; set; }
        public bool Approved { get; set; }
        public List<LineItem> Items { get; set; }
    }

    internal class LineItem
    {
        public string Product { get; set; }
        public int Discount { get; set; }
        public int Price { get; set; }
        public int QTY { get; set; }
    }
}
And the exception:
System.Exception was unhandled
  HResult=-2146233088
  Message=Failed to fast create instance for type 'ConsoleApplication.Program+SalesInvoiceViewRowSchema' from assemebly 'ConsoleApplication.Program+SalesInvoiceViewRowSchema, ConsoleApplication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
  Source=RaptorDB
  StackTrace:
       bei RaptorDB.Views.ViewHandler.FastCreateObject(Type objtype)
       bei RaptorDB.Views.ViewHandler.CreateResultRowFiller()
       bei RaptorDB.Views.ViewHandler.SetView[T](View`1 view, IDocStorage`1 docs)
       bei RaptorDB.Views.ViewManager.RegisterView[T](View`1 view)
       bei RaptorDB.RaptorDB.RegisterView[T](View`1 view)
       bei ConsoleApplication.Program.Main(String[] args) in c:\Users\Admin\Documents\Visual Studio 2013\Projects\ConsoleApplication\ConsoleApplication\Program.cs:Zeile 17.
       bei System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       bei System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       bei System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       bei System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       bei System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.MethodAccessException
       HResult=-2146233072
       Message=Fehler beim Versuch der Methode "DynamicClass._()", auf Methode "DynamicClass._()" zuzugreifen.
       Source=Anonymously Hosted DynamicMethods Assembly
       StackTrace:
            bei _()
            bei RaptorDB.Views.ViewHandler.FastCreateObject(Type objtype)
       InnerException: 
I hope you will be able to help me with this problem.
Thanks in advance!
Coordinator
Mar 17, 2015 at 5:29 AM
Your data entity classes should always be public -> change to public class SalesInvoice and public class LineItem .
Mar 17, 2015 at 7:46 AM
Thanks for the quick answer. While making the data entities public did not quite solve the problem, making the Program class public did.
Coordinator
Mar 17, 2015 at 8:51 AM
Yes the full path must be public.

I tried adding the .cs file as an attachment to the getting started but it doesn't work, so I have posted the source there.