Problem with Upsert in C# with lots of fields

Im trying to upsert a document with around 900 fields. Whenever I try to use the Bucket.Upsert with this many fields it gives an error. Underneath is the error:

The first line says says the MSIL-instruction is invalid or the index is out of the valid range.

The code for the upsert I got from the documentation, as you can see below

        for (int i = 0; i < 1; i++)
        {


            var document = new Document<dynamic>
            {
                Id = i.ToString(),
                Content = new
                {
                    Test = "Test"
                }
            };

            var upsert = bucket.Upsert(document);
            Console.WriteLine(upsert.Status);
            Console.WriteLine(upsert.Exception);
            if (upsert.Success)
            {
                var get = bucket.GetDocument<dynamic>(document.Id);
                Console.WriteLine("Inserted");
            }
        }

Within the content are the fields which I added. Whenever I reduce the fields to a lower amount, around 1/4 it has no problem. Is there a way to fix this problem without breaking up the document into pieces?

Hi @Semih and welcome to the forums!

Could you post the code that you are using? Are you using dynamic or an actual C# class?

Hello @matthew.groves ,

The full code is underneath:

static void Main(string[] args)
{
    Console.WriteLine("Hello world!");

    var cluster = new Cluster(new ClientConfiguration
    {
        Servers = new List<Uri> { new Uri("http://127.0.0.1:8091") }
    });

    var authenticator = new PasswordAuthenticator("Administrator", "admin123");
    cluster.Authenticate(authenticator);
    var bucket = cluster.OpenBucket("Test");

    for (int i = 0; i < 1; i++)
    {
        var document = new Document<dynamic>
        {
            Id = i.ToString(),
            Content = new
            {
                          // Fields here
            }
        };

        var upsert = bucket.Upsert(document);
        Console.WriteLine(upsert.Status);
        Console.WriteLine(upsert.Exception);
        if (upsert.Success)
        {
            var get = bucket.GetDocument<dynamic>(document.Id);
            Console.WriteLine("Inserted");
        }
    }
    
    Console.Read();
}
} 

I believe the dynamic is jus a C# class, I got it from https://docs.couchbase.com/dotnet-sdk/2.7/start-using-sdk.html#hello-couchbase

Hi @Semith,

I just tried (almost) exactly your code, and I did not get an error. I’m using Couchbase Server Enterprise 6.0.1 and the .NET SDK 2.7.7. I’m also using .NET Core 3.0 preview.

You commented out your object with // Fields here, so here is how I constructed a big object:

    var bigObject = new ExpandoObject() as IDictionary<string, object>;
    for (int x = 0; x < 900; x++)
        bigObject.Add("field" + x, "value" + x);

Which I then assigned to Content of document. My console program ran with no issues. Is there anything that jumps out at you as different between my setup and yours?