{"record":{"id":"de35f63bf8fffeb2","repo":"SignalR/SignalR","slug":"convert","errorCode":null,"errorMessage":"convert","messagePattern":"convert","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.AspNet.SignalR.Client/ObservableConnection.cs","lineNumber":26,"sourceCode":"\nnamespace Microsoft.AspNet.SignalR.Client\n{\n#if !PORTABLE\n    public class ObservableConnection<T> : IObservable<T>\n    {\n        private readonly Connection _connection;\n        private readonly Func<string, T> _convert;\n\n        public ObservableConnection(Connection connection, Func<string, T> convert)\n        {\n            if (connection == null)\n            {\n                throw new ArgumentNullException(\"connection\");\n            }\n\n            if (convert == null)\n            {\n                throw new ArgumentNullException(\"convert\");\n            }\n\n            _convert = convert;\n            _connection = connection;\n        }\n\n        public IDisposable Subscribe(IObserver<T> observer)\n        {\n            Action<string> received = data =>\n            {\n                observer.OnNext(_convert(data));\n            };\n\n            Action closed = () =>\n            {\n                observer.OnCompleted();\n            };\n","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/SignalR/SignalR/blob/693053b89a9e1f5ce819e3233ed159a6409de22b/src/Microsoft.AspNet.SignalR.Client/ObservableConnection.cs#L8-L44","documentation":"Thrown by the ObservableConnection<T> constructor when the 'convert' Func<string,T> is null. The observable converts each received JSON string to T before pushing it to observers, so the converter is mandatory.","triggerScenarios":"Constructing 'new ObservableConnection<T>(connection, null)'.","commonSituations":"Forgetting to supply a deserializer (e.g. JsonConvert.DeserializeObject<T>); refactoring that drops the lambda.","solutions":["Pass a non-null converter, e.g. 'data => JsonConvert.DeserializeObject<T>(data)'.","For raw strings, pass the identity: 'data => data'.","Null-check the converter at the call site if it comes from configuration."],"exampleFix":"// before\nvar obs = new ObservableConnection<MyType>(connection, null);\n\n// after\nvar obs = new ObservableConnection<MyType>(connection, data => JsonConvert.DeserializeObject<MyType>(data));","handlingStrategy":"validation","validationCode":"if (convert == null) throw new ArgumentNullException(nameof(convert));","typeGuard":"static bool IsValidConverter<T>(Func<string, T> f) => f != null;","tryCatchPattern":null,"preventionTips":["Always supply a converter (e.g. Json deserialize, or identity for strings).","Keep a named converter constant rather than inline lambdas that are easy to drop.","Unit-test the observable construction with a sample converter."],"tags":["csharp","signalr","null-argument","validation","reactive","serialization"],"backgroundTag":null,"analyzedSha":"693053b89a9e1f5ce819e3233ed159a6409de22b","analyzedAt":"2026-08-13T22:23:59.793Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}