{"record":{"id":"09c78b04b155023e","repo":"stride3d/stride","slug":"resource","errorCode":null,"errorMessage":"resource","messagePattern":"resource","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/GraphicsResourceLink.cs","lineNumber":21,"sourceCode":"\nusing System;\n\nnamespace Stride.Graphics;\n\n/// <summary>\n///   An object linking a Graphics Resource allocated by a <see cref=\"GraphicsResourceAllocator\"/>\n///   and providing allocation information.\n/// </summary>\npublic sealed class GraphicsResourceLink\n{\n    /// <summary>\n    ///   Initializes a new instance of the <see cref=\"GraphicsResourceLink\"/> class.\n    /// </summary>\n    /// <param name=\"resource\">The allocated Graphics Resource.</param>\n    /// <exception cref=\"ArgumentNullException\"><paramref name=\"resource\"/> is <see langword=\"null\"/>.</exception>\n    internal GraphicsResourceLink(GraphicsResourceBase resource)\n    {\n        Resource = resource ?? throw new ArgumentNullException(nameof(resource));\n    }\n\n\n    /// <summary>\n    ///   Gets the allocated Graphics Resource.\n    /// </summary>\n    public GraphicsResourceBase Resource { get; }\n\n    /// <summary>\n    ///   Gets the last time the Graphics Resource was accessed.\n    /// </summary>\n    public DateTime LastAccessTime { get; internal set; }\n\n    /// <summary>\n    ///   Gets the total number of times the Graphics Resource has been accessed (including Increment and Decrement).\n    /// </summary>\n    public long AccessTotalCount { get; internal set; }\n","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/GraphicsResourceLink.cs#L3-L39","documentation":"The GraphicsResourceLink constructor requires the allocated GraphicsResourceBase to be non-null; passing null throws ArgumentNullException with parameter name 'resource'. A link exists solely to hold a resource plus its reference counters, so a null resource is meaningless.","triggerScenarios":"Calling new GraphicsResourceLink(null), typically indirectly when an allocator cache entry is created from a resource lookup that returned null.","commonSituations":"Failed resource creation returning null yet being linked anyway; refactoring that removed a null check before constructing the link; reflection/DI constructing links without a resource.","solutions":["Ensure the resource creation call succeeded before constructing the link.","Add a null check or validation at the creation site so nulls never reach the link constructor."],"exampleFix":"// before\nvar link = new GraphicsResourceLink(CreateResourceMaybeNull());\n// after\nvar res = CreateResourceMaybeNull() ?? throw new InvalidOperationException(\"resource creation failed\");\nvar link = new GraphicsResourceLink(res);","handlingStrategy":"validation","validationCode":"var res = CreateResource();\nif (res is null) throw new InvalidOperationException(\"resource creation failed\");\nvar link = new GraphicsResourceLink(res);","typeGuard":"bool HasResource(GraphicsResourceBase r) => r is not null;","tryCatchPattern":"try { link = new GraphicsResourceLink(resource); }\ncatch (ArgumentNullException ex) { log.Error(\"null resource\", ex); throw; }","preventionTips":["Check creation results before linking","Never construct links from nullable lookups without checks"],"tags":["csharp","null-argument","graphics"],"backgroundTag":"null-argument","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}