Problem with Upsert in C# with lots of fields

.net
#1

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?

#2

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?

#3

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