{"record":{"id":"0f8a1ed6450f356f","repo":"SixLabors/ImageSharp","slug":"source","errorCode":null,"errorMessage":"source","messagePattern":"source","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/Advanced/AdvancedImageExtensions.cs","lineNumber":102,"sourceCode":"    /// <param name=\"visitor\">The image visitor.</param>\n    public static void AcceptVisitor(this ImageFrame source, IImageFrameVisitor visitor)\n        => source.Accept(visitor);\n\n    /// <summary>\n    /// Gets the representation of the pixels as a <see cref=\"IMemoryGroup{T}\"/> containing the backing pixel data of the image\n    /// stored in row major order, as a list of contiguous <see cref=\"Memory{T}\"/> blocks in the source image's pixel format.\n    /// </summary>\n    /// <param name=\"source\">The source image.</param>\n    /// <typeparam name=\"TPixel\">The type of the pixel.</typeparam>\n    /// <returns>The <see cref=\"IMemoryGroup{T}\"/>.</returns>\n    /// <remarks>\n    /// Certain Image Processors may invalidate the returned <see cref=\"IMemoryGroup{T}\"/> and all it's buffers,\n    /// therefore it's not recommended to mutate the image while holding a reference to it's <see cref=\"IMemoryGroup{T}\"/>.\n    /// </remarks>\n    /// <exception cref=\"ArgumentNullException\">Thrown when the <paramref name=\"source\"/> in <see langword=\"null\"/>.</exception>\n    public static IMemoryGroup<TPixel> GetPixelMemoryGroup<TPixel>(this ImageFrame<TPixel> source)\n        where TPixel : unmanaged, IPixel<TPixel>\n        => source?.PixelBuffer.FastMemoryGroup.View ?? throw new ArgumentNullException(nameof(source));\n\n    /// <summary>\n    /// Gets the representation of the pixels as a <see cref=\"IMemoryGroup{T}\"/> containing the backing pixel data of the image\n    /// stored in row major order, as a list of contiguous <see cref=\"Memory{T}\"/> blocks in the source image's pixel format.\n    /// </summary>\n    /// <param name=\"source\">The source image.</param>\n    /// <typeparam name=\"TPixel\">The type of the pixel.</typeparam>\n    /// <returns>The <see cref=\"IMemoryGroup{T}\"/>.</returns>\n    /// <remarks>\n    /// Certain Image Processors may invalidate the returned <see cref=\"IMemoryGroup{T}\"/> and all it's buffers,\n    /// therefore it's not recommended to mutate the image while holding a reference to it's <see cref=\"IMemoryGroup{T}\"/>.\n    /// </remarks>\n    /// <exception cref=\"ArgumentNullException\">Thrown when the <paramref name=\"source\"/> in <see langword=\"null\"/>.</exception>\n    public static IMemoryGroup<TPixel> GetPixelMemoryGroup<TPixel>(this Image<TPixel> source)\n        where TPixel : unmanaged, IPixel<TPixel>\n        => source?.Frames.RootFrame.GetPixelMemoryGroup() ?? throw new ArgumentNullException(nameof(source));\n\n    /// <summary>","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/Advanced/AdvancedImageExtensions.cs#L84-L120","documentation":"GetPixelMemoryGroup on ImageFrame<TPixel> throws ArgumentNullException when the source frame reference is null. It uses the null-coalescing throw pattern: source?.PixelBuffer... ?? throw new ArgumentNullException(nameof(source)).","triggerScenarios":"Calling frame.GetPixelMemoryGroup() (or image.Frames.RootFrame chain) where the ImageFrame<TPixel> variable is null — typically a failed lookup, an uninitialized field, or passing null through a generic helper.","commonSituations":"Storing frames in a dictionary/collection and retrieving with a key that yields null; passing a null frame into a generic pixel-processing helper; calling image.Frames.RootFrame logic on a wrapper that defaulted to null.","solutions":["Ensure the ImageFrame<TPixel> reference is non-null before calling GetPixelMemoryGroup","Check how the frame was obtained (indexer, search, factory) and validate the result","Throw/validate early with Guard.NotNull or an explicit null check at your API boundary"],"exampleFix":"// before\nvar group = maybeFrame.GetPixelMemoryGroup();\n// after\nif (maybeFrame is null) throw new InvalidOperationException(\"Frame not found\");\nvar group = maybeFrame.GetPixelMemoryGroup();","handlingStrategy":"type-guard","validationCode":"if (frame is null) throw new InvalidOperationException(\"Frame must be resolved before pixel access\");","typeGuard":"bool HasFrame(ImageFrame<TPixel>? frame) => frame is not null;","tryCatchPattern":"try { var group = frame.GetPixelMemoryGroup(); }\ncatch (ArgumentNullException ex) { logger.LogError(ex, \"Frame was null\"); }","preventionTips":["Never cache ImageFrame references across image disposal/reconfiguration","Check the return of frame lookups (Frames.IndexerFrame etc.) for null before use","Validate inputs at your public helper boundaries with Guard.NotNull"],"tags":["null-argument","pixels","memory","argument"],"backgroundTag":"null-argument","analyzedSha":"59ce6af6fc29027cda277ef62d4d1694a8acce91","analyzedAt":"2026-09-13T18:34:59.331Z","contentChangedAt":"2026-09-13T18:34:59.331Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}