{"record":{"id":"9acd04c285396e3d","repo":"JamesNK/Newtonsoft.Json","slug":"cannot-get-serializationbinder-because-an-iseriali","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/JsonSerializer.cs","lineNumber":123,"sourceCode":"        /// <summary>\n        /// Gets or sets the <see cref=\"SerializationBinder\"/> used by the serializer when resolving type names.\n        /// </summary>\n        [Obsolete(\"Binder is obsolete. Use SerializationBinder instead.\")]\n        public virtual SerializationBinder Binder\n        {\n            get\n            {\n                if (_serializationBinder is SerializationBinder legacySerializationBinder)\n                {\n                    return legacySerializationBinder;\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\n            {\n                if (value == null)\n                {\n                    throw new ArgumentNullException(nameof(value), \"Serialization binder cannot be null.\");\n                }\n\n                _serializationBinder = value as ISerializationBinder ?? new SerializationBinderAdapter(value);\n            }\n        }\n\n        /// <summary>\n        /// Gets or sets the <see cref=\"ISerializationBinder\"/> used by the serializer when resolving type names.\n        /// </summary>\n        public virtual ISerializationBinder SerializationBinder\n        {\n            get => _serializationBinder;","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/JsonSerializer.cs#L105-L141","documentation":"Thrown by the obsolete JsonSerializer.Binder getter (legacy SerializationBinder API) when the field holds an ISerializationBinder that is neither a SerializationBinder subclass nor a SerializationBinderAdapter. Because the new ISerializationBinder abstraction is broader than the legacy abstract SerializationBinder class, the getter cannot losslessly return it, so it throws InvalidOperationException. The fix is to use the SerializationBinder (ISerializationBinder) property instead of the obsolete Binder.","triggerScenarios":"Reading serializer.Binder after serializer.SerializationBinder was set to a custom ISerializationBinder implementation that does not derive from the legacy SerializationBinder class.","commonSituations":"Interoperating with code/libraries that still use the obsolete Binder property; migrating from the legacy API; a DI-registered ISerializationBinder being assigned then legacy code reading Binder.","solutions":["Switch all reads/writes to the SerializationBinder property (ISerializationBinder) and stop using the obsolete Binder.","If a legacy SerializationBinder is required, assign via the Binder setter so it is wrapped in a SerializationBinderAdapter the getter can unwrap.","Suppress the Obsolete warning only after migrating callers off Binder."],"exampleFix":"// before\nvar b = serializer.Binder; // throws if ISerializationBinder set\n\n// after\nISerializationBinder b = serializer.SerializationBinder;","handlingStrategy":"validation","validationCode":"#pragma warning disable CS0618\nSerializationBinder legacy = null;\ntry { legacy = serializer.Binder; }\ncatch (InvalidOperationException) { /* use SerializationBinder instead */ }\n#pragma warning restore CS0618","typeGuard":"static bool CanReadLegacyBinder(JsonSerializer s)\n{\n    var b = s.SerializationBinder;\n    return b is SerializationBinder or SerializationBinderAdapter;\n}","tryCatchPattern":null,"preventionTips":["Migrate all code off the obsolete Binder property.","If legacy access is unavoidable, assign binders via the Binder setter so they stay adapter-wrapped.","Wrap legacy consumers behind a shim that reads SerializationBinder."],"tags":["obsolete-api","serialization-binder","configuration"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}