{"record":{"id":"aa9e6c62e22a9a19","repo":"JamesNK/Newtonsoft.Json","slug":"cannot-get-serializationbinder-because-an-iseriali-aa9e6c","errorCode":null,"errorMessage":"Cannot get SerializationBinder because an ISerializationBinder was previously set.","messagePattern":"Cannot get SerializationBinder because an ISerializationBinder was previously set\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Src/Newtonsoft.Json/JsonSerializerSettings.cs","lineNumber":290,"sourceCode":"        /// Gets or sets the <see cref=\"SerializationBinder\"/> used by the serializer when resolving type names.\n        /// </summary>\n        /// <value>The binder.</value>\n        [Obsolete(\"Binder is obsolete. Use SerializationBinder instead.\")]\n        public SerializationBinder? Binder\n        {\n            get\n            {\n                if (SerializationBinder == null)\n                {\n                    return null;\n                }\n\n                if (SerializationBinder is SerializationBinderAdapter adapter)\n                {\n                    return adapter.SerializationBinder;\n                }\n\n                throw new InvalidOperationException(\"Cannot get SerializationBinder because an ISerializationBinder was previously set.\");\n            }\n            set => SerializationBinder = value == null ? null : new SerializationBinderAdapter(value);\n        }\n\n        /// <summary>\n        /// Gets or sets the <see cref=\"ISerializationBinder\"/> used by the serializer when resolving type names.\n        /// </summary>\n        /// <value>The binder.</value>\n        public ISerializationBinder? SerializationBinder { get; set; }\n\n        /// <summary>\n        /// Gets or sets the error handler called during serialization and deserialization.\n        /// </summary>\n        /// <value>The error handler called during serialization and deserialization.</value>\n        public EventHandler<ErrorEventArgs>? Error { get; set; }\n\n        /// <summary>\n        /// Gets or sets the <see cref=\"StreamingContext\"/> used by the serializer when invoking serialization callback methods.","sourceCodeStart":272,"sourceCodeEnd":308,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/JsonSerializerSettings.cs#L272-L308","documentation":"Thrown by the obsolete JsonSerializerSettings.Binder getter when the underlying SerializationBinder (ISerializationBinder) was set to a type that is neither a SerializationBinderAdapter nor directly a legacy SerializationBinder. The new ISerializationBinder contract is broader than the obsolete abstract class, so the getter cannot represent it and throws InvalidOperationException. Migrate reads to the SerializationBinder property.","triggerScenarios":"Reading settings.Binder (obsolete) after settings.SerializationBinder was assigned a custom ISerializationBinder not derived from legacy SerializationBinder.","commonSituations":"Libraries/serializers still consuming the obsolete Binder property; migration from legacy API; DI-registered ISerializationBinder assigned then legacy code reads Binder.","solutions":["Read/write through the SerializationBinder (ISerializationBinder) property exclusively.","If the legacy SerializationBinder object is genuinely needed, assign it via the Binder setter so it is stored as an adapter the getter understands.","Update all consumers off the obsolete property and clear the Obsolete warning."],"exampleFix":"// before\nSerializationBinder b = settings.Binder; // throws\n\n// after\nISerializationBinder b = settings.SerializationBinder;","handlingStrategy":"validation","validationCode":"#pragma warning disable CS0618\nSerializationBinder legacy = null;\ntry { legacy = settings.Binder; }\ncatch (InvalidOperationException) { /* read settings.SerializationBinder instead */ }\n#pragma warning restore CS0618","typeGuard":"static bool CanReadLegacyBinder(JsonSerializerSettings s)\n{\n    var b = s.SerializationBinder;\n    return b is null or SerializationBinderAdapter or SerializationBinder;\n}","tryCatchPattern":null,"preventionTips":["Migrate consumers to the SerializationBinder (ISerializationBinder) property.","Assign via Binder setter only when the legacy type is genuinely needed (it wraps in an adapter).","Centralize binder access behind a helper to avoid scattered obsolete reads."],"tags":["obsolete-api","serialization-binder","configuration"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}