{"record":{"id":"8485978a4aa384a5","repo":"stride3d/stride","slug":"device","errorCode":null,"errorMessage":"device","messagePattern":"device","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/Effects/Effect.cs","lineNumber":49,"sourceCode":"        /// <summary>\n        /// Initializes a new instance of the <see cref=\"Effect\"/> class.\n        /// </summary>\n        /// <param name=\"device\">The device.</param>\n        /// <param name=\"bytecode\">The bytecode.</param>\n        /// <param name=\"usedParameters\">The parameters used to create this shader (from a sdfx).</param>\n        /// <exception cref=\"System.ArgumentNullException\">\n        /// device\n        /// or\n        /// bytecode\n        /// </exception>\n        public Effect(GraphicsDevice device, EffectBytecode bytecode)\n        {\n            InitializeFrom(device, bytecode);\n        }\n\n        internal void InitializeFrom(GraphicsDevice device, EffectBytecode bytecode)\n        {\n            if (device == null) throw new ArgumentNullException(\"device\");\n            if (bytecode == null) throw new ArgumentNullException(\"bytecode\");\n\n            this.graphicsDeviceDefault = device;\n            this.bytecode = bytecode;\n            Initialize();\n        }\n\n        /// <summary>\n        /// Gets the bytecode.\n        /// </summary>\n        /// <value>The bytecode.</value>\n        public EffectBytecode Bytecode\n        {\n            get\n            {\n                return bytecode;\n            }\n        }","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/Effects/Effect.cs#L31-L67","documentation":"Effect.InitializeFrom throws ArgumentNullException with parameter name \"device\" when a null GraphicsDevice is passed while constructing or initializing an Effect from EffectBytecode. The effect needs a valid device to initialize its internal resource bindings.","triggerScenarios":"Calling new Effect(device, bytecode) or effect.InitializeFrom(device, bytecode) with a null device — e.g. a GraphicsDevice field not yet assigned in a constructor, or deserialization producing a null device.","commonSituations":"Game code creating effects before the GraphicsService/Game instance is ready; dependency-injection ordering issues where the device property is still null; unit tests passing null.","solutions":["Ensure a valid, initialized GraphicsDevice is created before constructing any Effect.","Fix initialization order: create the device first, then load effects (e.g. in Game.LoadContent).","Add null checks/asserts upstream so the device is resolved before reaching Effect construction."],"exampleFix":"// before\nvar effect = new Effect(null, bytecode);\n// after\nvar effect = new Effect(graphicsDevice, bytecode); // graphicsDevice must be non-null","handlingStrategy":"validation","validationCode":"if (graphicsDevice == null)\n    throw new InvalidOperationException(\"GraphicsDevice must be initialized before creating an Effect\");\nvar effect = new Effect(graphicsDevice, bytecode);","typeGuard":"bool HasValidDevice(GraphicsDevice d) => d is { IsDisposed: false };","tryCatchPattern":"try { effect = new Effect(device, bytecode); }\ncatch (ArgumentNullException ex) { log.Error(ex, \"Effect created with null device — check init order\"); throw; }","preventionTips":["Create effects only after GraphicsDevice is fully initialized (e.g. in LoadContent).","Avoid storing the device in a nullable field read during construction before assignment.","Add constructor guards in wrappers around Effect creation."],"tags":["argument-null","effect","graphics-device"],"backgroundTag":"null-argument","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}