Editor .Net Core: System.ArgumentNullException: 'Value cannot be null. '

Editor .Net Core: System.ArgumentNullException: 'Value cannot be null. '

equezadajejequezadajej Posts: 8Questions: 2Answers: 0

I'm using Editor 2.0.8 for .Net Core and I got into the following issue and the exception doesn't have enough details to know why it's happening:

It's able to correctly upload the file, but it fails when I try adding to the table TBOrdenCompra.


   at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
   at DataTables.Editor._InsertOrUpdate(Object id, Dictionary`2 values)
   at DataTables.Editor._Insert(Dictionary`2 values)
   at DataTables.Editor._Process(DtRequest data)
   at DataTables.Editor.Process(DtRequest data)
   at DataTables.Editor.Process(IEnumerable`1 data, String culture)
   at DataTables.Editor.Process(HttpRequest request, String culture)
   at SistemaInventario.Controllers.MantenedoresController.OrdenDeCompra() in C:\Repositorios\Web\HH2.2\SistemaInventario\Controllers\MantenedoresController.cs:line 189
   at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()

Controller code:

        public ActionResult OrdenDeCompra()
            var dbType = Environment.GetEnvironmentVariable("DBTYPE");
            var dbConnection = Environment.GetEnvironmentVariable("DBCONNECTION");

            using (var db = new Database(dbType, dbConnection))
                var update = Format.DATE_ISO_8601;
                var response = new Editor(db, "DBInventario.dbo.TBOrdenCompra", "idOrdenCompra")
                    .Field(new Field("DBInventario.dbo.TBOrdenCompra.idOrdenCompra"))
                    .Field(new Field("DBInventario.dbo.TBOrdenCompra.folioOrdenCompra")
                        .Validator(Validation.NotEmpty(new ValidationOpts { Message = "Campo requerido." }))
                        .Xss(false) //Permitir Acentos (á)
                    .Field(new Field("DBInventario.dbo.TBOrdenCompra.fechaOrdenCompra")
                            new ValidationOpts { Message = "Ingrese fecha en formato aaaa-mm-dd." }
                    .Field(new Field("DBInventario.dbo.TBOrdenCompra.idCliente")
                        .Options(new DataTables.Options()
                            .Label(new List<string> { "IDCliente", "Descripcion"})
                    .Field(new Field("DBInventario.dbo.TBOrdenCompra.idArchivo")
                        .Validator(Validation.NotEmpty(new ValidationOpts { Message = "Documento requerido." }))
                        .Upload(new Upload(Path.Combine(System.IO.Directory.GetCurrentDirectory(), "wwwroot", "uploads/ordenesDeCompra", "__ID____EXTN__"))
                            .Db("TBArchivos", "idArchivo", new Dictionary<string, object>
                                {"rutaWeb", Path.DirectorySeparatorChar+Path.Combine("uploads/ordenesDeCompra", "__ID____EXTN__")},
                                {"rutaSistema", Upload.DbType.SystemPath},
                                {"nombreArchivo", Upload.DbType.FileName},
                                {"tamanoArchivo", Upload.DbType.FileSize}
                            .DbClean(data =>
                                foreach (var row in data)
                                    // Do something;
                                return true;
                            .Validator(Validation.FileSize(5000000, "Excede tamaño máximo 5MB."))
                            .Validator(Validation.FileExtensions(new[] { "pdf" }, "Sólo se admite extensión PDF."))
                    .LeftJoin("DBCentral.dbo.TB11Clientes", "DBInventario.dbo.TBOrdenCompra.idCliente", "=", "DBCentral.dbo.TB11Clientes.idCliente")
                response.PostCreate += (sender, e) => _LogChange(db, 1, e.Id, e.Values);
                response.PostEdit += (sender, e) => _LogChange(db, 2, e.Id, e.Values);
                response.PostRemove += (sender, e) => _LogChange(db, 3, e.Id, e.Values);

                var aaaa = response.Process(Request);
                var bbbb = aaaa.Data();

                return Json(bbbb);

Client initialization:

    var editor; // use a global for the submit and return data rendering in the examples

    $(document).ready(function () {
        editor = new $.fn.dataTable.Editor({
            ajax: "/api/OrdenDeCompra",
            table: "#example",
            fields: [
                    label: "Folio OC",
                    name: "DBInventario.dbo.TBOrdenCompra.folioOrdenCompra"
                    label: 'Fecha OC',
                    name: 'DBInventario.dbo.TBOrdenCompra.fechaOrdenCompra',
                    type: 'datetime',
                    def: function () { return new Date(); }
                }, {
                    label: "N° Centro Costo",
                    name: "DBInventario.dbo.TBOrdenCompra.idCliente",
                    type: "select2",
                }, {
                    label: "Archivo",
                    name: "DBInventario.dbo.TBOrdenCompra.idArchivo",
                    type: "upload",
                    display: function (file_id) {
                        return '<a href="' + editor.file('TBArchivos', file_id).rutaWeb + '" target="_blank">Descargar</a>';
                    clearText: "Eliminar",
                    noImageText: 'Sin Archivo',
                    noFileText: 'Sin archivo elegido',
                    uploadText: 'Elegir archivo...',
                    dragDropText: 'Arrastra y suelta el archivo aquí para subir'

            dom: "Bfrtip",
            ajax: "/api/OrdenDeCompra",
            columns: [
                { data: "idOrdenCompra" },
                { data: "folioOrdenCompra" },
                { data: 'fechaOrdenCompra' },
                    data: "idArchivo",
                    render: function (file_id) {
                        return file_id ?
                            'Archivo cargado' :
                    defaultContent: "Sin archivo",
                    title: "Archivo"
            order: [
                //[3, 'asc'], [0, 'asc']
            select: true,
            buttons: [
                { extend: "create", editor: editor },
                { extend: "edit", editor: editor },
                { extend: "remove", editor: editor }

SQL Server Tables:

CREATE TABLE [dbo].[TBOrdenCompra](
    [idOrdenCompra] [int] IDENTITY(1,1) NOT NULL,
    [folioOrdenCompra] [varchar](30) NOT NULL,
    [fechaOrdenCompra] [date] NOT NULL,
    [idCliente] [int] NOT NULL,
    [idArchivo] [int] NULL,
 CONSTRAINT [PK_TBOrdenCompra] PRIMARY KEY (idOrdenCompra),
 CONSTRAINT [FK_TBOrdenCompra_1] FOREIGN KEY ([idArchivo]) REFERENCES [dbo].[TBArchivos] ([idArchivo])
CREATE TABLE [dbo].[TBArchivos](
    [idArchivo] [int] IDENTITY(1,1) NOT NULL,
    [nombreArchivo] [nvarchar](250) NULL,
    [tamanoArchivo] [int] NULL,
    [rutaWeb] [nvarchar](250) NULL,
    [rutaSistema] [nvarchar](250) NULL,
 CONSTRAINT [PK_TBArchivos] PRIMARY KEY ([idArchivo])


  • allanallan Posts: 57,263Questions: 1Answers: 9,121 Site admin


    I suspect it is something to do with the use of the schema name. Is this error happening after the upload has completed and you then submit the form, or while you are uploading the file? From the error message and backtrace, I suspect the former. If that is the case, can you show me the response from the server for the upload action please?

    Many thanks,

  • equezadajejequezadajej Posts: 8Questions: 2Answers: 0

    Hi Allan,
    It is happening after the upload, when submitting the form.
    I can confirm that it at least uploads the file and inserts the data to the TBArchivos SQL table.

    Server's response of the upload action:

    {"draw":null,"data":[],"recordsTotal":null,"recordsFiltered":null,"error":null,"fieldErrors":[],"id":null,"meta":{},"options":{},"searchPanes":{"options":{}},"files":{"TBArchivos":{"35":{"idArchivo":35,"rutaWeb":"\\uploads/ordenesDeCompra\\35.pdf","rutaSistema":"C:\\Repositorios\\Web\\HH2.2\\SistemaInventario\\wwwroot\\uploads/ordenesDeCompra\\35.pdf","nombreArchivo":"pcr_20220509.pdf","tamanoArchivo":220676}}},"upload":{"id":"35"},"debug":[{"query":"DECLARE @T TABLE ( insert_id int ); INSERT INTO  [TBArchivos]  ( [rutaWeb], [rutaSistema], [nombreArchivo], [tamanoArchivo] ) OUTPUT INSERTED.idArchivo as insert_id INTO @T VALUES (  @rutaWeb,  @rutaSistema,  @nombreArchivo,  @tamanoArchivo ); SELECT insert_id FROM @T","bindings":[{"name":"@rutaWeb","value":"-","type":null},{"name":"@rutaSistema","value":"-","type":null},{"name":"@nombreArchivo","value":"pcr_20220509.pdf","type":null},{"name":"@tamanoArchivo","value":220676,"type":null}]},{"query":"UPDATE  [TBArchivos] SET  [rutaWeb] = @rutaWeb, [rutaSistema] = @rutaSistema WHERE [idArchivo] = @where_0 ","bindings":[{"name":"@where_0","value":"35","type":null},{"name":"@rutaWeb","value":"\\uploads/ordenesDeCompra\\35.pdf","type":null},{"name":"@rutaSistema","value":"C:\\Repositorios\\Web\\HH2.2\\SistemaInventario\\wwwroot\\uploads/ordenesDeCompra\\35.pdf","type":null}]},{"query":"SELECT  [idArchivo] as 'idArchivo', [rutaWeb] as 'rutaWeb', [rutaSistema] as 'rutaSistema', [nombreArchivo] as 'nombreArchivo', [tamanoArchivo] as 'tamanoArchivo' FROM  [TBArchivos] WHERE [idArchivo] IN (@wherein1) ","bindings":[{"name":"@wherein1","value":"35","type":null}]}],"cancelled":[]}
  • allanallan Posts: 57,263Questions: 1Answers: 9,121 Site admin

    Super - thanks for that. I will try to reproduce the issue here with that information and get back to you. The upload response looks good - so I suspect it is how the field name is handled with the multi-levels of nesting.


  • equezadajejequezadajej Posts: 8Questions: 2Answers: 0

    Any news about this?

  • allanallan Posts: 57,263Questions: 1Answers: 9,121 Site admin

    Apologies, not yet. I've not yet had a chance to build up an example. Hoping to do so soon.


Sign In or Register to comment.