{"record":{"id":"e27b71a45c044ad0","repo":"dotnet/AspNetCore.Docs","slug":"ko-mapping-defaultoptions-ignore-should-be-an-ar-e27b71","errorCode":null,"errorMessage":"ko.mapping.defaultOptions().ignore should be an array.","messagePattern":"ko\\.mapping\\.defaultOptions\\(\\)\\.ignore should be an array\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"aspnetcore/mvc/controllers/testing/samples/3.x/TestingControllersSample/src/TestingControllersSample/wwwroot/js/knockout.mapping.js","lineNumber":155,"sourceCode":"\texports.fromJSON = function (jsonString /*, options, target*/ ) {\n\t\tvar parsed = ko.utils.parseJson(jsonString);\n\t\targuments[0] = parsed;\n\t\treturn exports.fromJS.apply(this, arguments);\n\t};\n\n\texports.updateFromJS = function (viewModel) {\n\t\tthrow new Error(\"ko.mapping.updateFromJS, use ko.mapping.fromJS instead. Please note that the order of parameters is different!\");\n\t};\n\n\texports.updateFromJSON = function (viewModel) {\n\t\tthrow new Error(\"ko.mapping.updateFromJSON, use ko.mapping.fromJSON instead. Please note that the order of parameters is different!\");\n\t};\n\n\texports.toJS = function (rootObject, options) {\n\t\tif (!defaultOptions) exports.resetDefaultOptions();\n\n\t\tif (arguments.length == 0) throw new Error(\"When calling ko.mapping.toJS, pass the object you want to convert.\");\n\t\tif (exports.getType(defaultOptions.ignore) !== \"array\") throw new Error(\"ko.mapping.defaultOptions().ignore should be an array.\");\n\t\tif (exports.getType(defaultOptions.include) !== \"array\") throw new Error(\"ko.mapping.defaultOptions().include should be an array.\");\n\t\tif (exports.getType(defaultOptions.copy) !== \"array\") throw new Error(\"ko.mapping.defaultOptions().copy should be an array.\");\n\n\t\t// Merge in the options used in fromJS\n\t\toptions = fillOptions(options, rootObject[mappingProperty]);\n\n\t\t// We just unwrap everything at every level in the object graph\n\t\treturn exports.visitModel(rootObject, function (x) {\n\t\t\treturn ko.utils.unwrapObservable(x)\n\t\t}, options);\n\t};\n\n\texports.toJSON = function (rootObject, options) {\n\t\tvar plainJavaScriptObject = exports.toJS(rootObject, options);\n\t\treturn ko.utils.stringifyJson(plainJavaScriptObject);\n\t};\n\n\texports.defaultOptions = function () {","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/dotnet/AspNetCore.Docs/blob/c67a80103a1a74db20784debd919c7fdda96c510/aspnetcore/mvc/controllers/testing/samples/3.x/TestingControllersSample/src/TestingControllersSample/wwwroot/js/knockout.mapping.js#L137-L173","documentation":"knockout.mapping.js validates that `defaultOptions().ignore` is an array before processing, throwing if it is not. ignore controls which properties mapping skips; a non-array breaks the array-filtering logic downstream.","triggerScenarios":"Setting `ko.mapping.defaults.ignore` (or via defaultOptions) to a non-array value such as a string or object, then calling any mapping function that reads defaultOptions (fromJS, toJS, etc.).","commonSituations":"Typo like `ignore: \"id\"` instead of `ignore: [\"id\"]`; merging options where a scalar overwrote the array; copying config from a tutorial that used the wrong shape.","solutions":["Ensure ignore is an array of property-name strings: `ko.mapping.defaults.ignore = [\"id\", \"_internal\"];`.","Reset to defaults with `ko.mapping.resetDefaultOptions()` if the state is corrupted.","Audit every place that writes to `ko.mapping.defaults` / `defaultOptions()` and confirm each of ignore/include/copy is an array."],"exampleFix":"// before\nko.mapping.defaults.ignore = \"id\";\n\n// after\nko.mapping.defaults.ignore = [\"id\"];","handlingStrategy":"validation","validationCode":"function setIgnore(props) {\n  if (!Array.isArray(props)) throw new TypeError('ignore must be an array');\n  ko.mapping.defaults.ignore = props;\n}","typeGuard":"function isValidOptionArray(v) {\n  return Array.isArray(v) && v.every(x => typeof x === 'string');\n}","tryCatchPattern":"// Rarely caught — fix config instead. Validate at startup:\nif (!Array.isArray(ko.mapping.defaults.ignore)) {\n  ko.mapping.resetDefaultOptions();\n}","preventionTips":["Set defaults in one bootstrap module.","Use array literals `[\"id\"]`, never bare strings.","Unit-test that ignore/include/copy are arrays after setup."],"tags":["knockout","configuration","type-error","mapping"],"backgroundTag":null,"analyzedSha":"c67a80103a1a74db20784debd919c7fdda96c510","analyzedAt":"2026-08-13T17:46:11.763Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}