{"record":{"id":"37d5728cb17721ba","repo":"dotnet/orleans","slug":"dataadapter","errorCode":null,"errorMessage":"dataAdapter","messagePattern":"dataAdapter","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Azure/Orleans.Streaming.EventHubs/Providers/Streams/EventHub/EventHubAdapterFactory.cs","lineNumber":124,"sourceCode":"\n        public EventHubAdapterFactory(\n            string name,\n            EventHubOptions ehOptions,\n            EventHubReceiverOptions receiverOptions,\n            EventHubStreamCachePressureOptions cacheOptions, \n            StreamCacheEvictionOptions cacheEvictionOptions,\n            StreamStatisticOptions statisticOptions,\n            IEventHubDataAdapter dataAdapter,\n            IServiceProvider serviceProvider,\n            ILoggerFactory loggerFactory,\n            IEnvironmentStatisticsProvider environmentStatisticsProvider)\n        {\n            this.Name = name;\n            this.cacheEvictionOptions = cacheEvictionOptions ?? throw new ArgumentNullException(nameof(cacheEvictionOptions));\n            this.statisticOptions = statisticOptions ?? throw new ArgumentNullException(nameof(statisticOptions));\n            this.ehOptions = ehOptions ?? throw new ArgumentNullException(nameof(ehOptions));\n            this.cacheOptions = cacheOptions?? throw new ArgumentNullException(nameof(cacheOptions));\n            this.dataAdapter = dataAdapter ?? throw new ArgumentNullException(nameof(dataAdapter));\n            this.receiverOptions = receiverOptions?? throw new ArgumentNullException(nameof(receiverOptions));\n            this.serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));\n            this.loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));\n            this.environmentStatisticsProvider = environmentStatisticsProvider;\n            this.orleansInstruments = serviceProvider.GetRequiredService<OrleansInstruments>();\n        }\n\n        public virtual void Init()\n        {\n            this.receivers = new ConcurrentDictionary<QueueId, EventHubAdapterReceiver>();\n\n            InitEventHubClient();\n\n            if (this.CacheFactory == null)\n            {\n                this.CacheFactory = CreateCacheFactory(this.cacheOptions).CreateCache;\n            }\n","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/dotnet/orleans/blob/fca799fa70ecb6ad975224271703ca43221f58de/src/Azure/Orleans.Streaming.EventHubs/Providers/Streams/EventHub/EventHubAdapterFactory.cs#L106-L142","documentation":"EventHubAdapterFactory requires a non-null IEventHubDataAdapter because it is the core bridge between Event Hub EventData and Orleans stream types (StreamId, StreamSequenceToken, CachedMessage, IBatchContainer). Without it the adapter cannot serialize batch containers, compute partition keys, or translate incoming messages. The default implementation is EventHubDataAdapter, which users may subclass to customize mapping.","triggerScenarios":"Constructing EventHubAdapterFactory directly with dataAdapter set to null. In the default factory Create method, the data adapter is resolved as services.GetKeyedService<IEventHubDataAdapter>(name) ?? services.GetService<IEventHubDataAdapter>() ?? ActivatorUtilities.CreateInstance<EventHubDataAdapter>(services), which guarantees a non-null value — so this only fires on manual construction or a custom factory that explicitly returns null.","commonSituations":"Manually building the adapter in tests or a custom factory and forgetting the dataAdapter argument; a DI container where an IEventHubDataAdapter registration is accidentally registered as null via a factory lambda returning null.","solutions":["If constructing manually, pass new EventHubDataAdapter(services.GetRequiredService<Serializer>()) or your custom IEventHubDataAdapter implementation.","If using standard DI, rely on the built-in Create factory which auto-creates EventHubDataAdapter when none is registered.","If registering a custom IEventHubDataAdapter, verify the registration factory never returns null."],"exampleFix":"// before\nvar factory = new EventHubAdapterFactory(\n    name, ehOptions, receiverOptions, cacheOptions, evictionOpts, statOpts, null /* dataAdapter */, services, loggerFactory, envStats);\n\n// after\nvar dataAdapter = new EventHubDataAdapter(services.GetRequiredService<Orleans.Serialization.Serializer>());\nvar factory = new EventHubAdapterFactory(\n    name, ehOptions, receiverOptions, cacheOptions, evictionOpts, statOpts, dataAdapter, services, loggerFactory, envStats);","handlingStrategy":"validation","validationCode":"// Before constructing manually:\nIEventHubDataAdapter dataAdapter = customAdapter\n    ?? new EventHubDataAdapter(services.GetRequiredService<Orleans.Serialization.Serializer>());","typeGuard":"static bool IsValidDataAdapter(IEventHubDataAdapter adapter)\n    => adapter is not null;","tryCatchPattern":null,"preventionTips":["Rely on the built-in Create factory which auto-creates EventHubDataAdapter when no IEventHubDataAdapter is registered.","When registering a custom IEventHubDataAdapter in DI, verify the factory lambda never returns null.","In tests, construct EventHubDataAdapter with a real or mock Orleans.Serializer."],"tags":["configuration","dependency-injection","eventhub","constructor","null-argument","data-adapter"],"backgroundTag":null,"analyzedSha":"fca799fa70ecb6ad975224271703ca43221f58de","analyzedAt":"2026-08-13T19:55:57.938Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}