{"record":{"id":"df91c72a9291efa0","repo":"SixLabors/ImageSharp","slug":"newly-created-value-for-tag-tag-is-null","errorCode":null,"errorMessage":"Newly created value for tag {tag} is null.","messagePattern":"Newly created value for tag (.+?) is null\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/Metadata/Profiles/Exif/ExifProfile.cs","lineNumber":288,"sourceCode":"\n    /// <summary>\n    /// Sets the value of the specified tag.\n    /// </summary>\n    /// <param name=\"tag\">The tag of the Exif value.</param>\n    /// <param name=\"value\">The value.</param>\n    /// <exception cref=\"NotSupportedException\">The newly created value is null.</exception>\n    internal void SetValueInternal(ExifTag tag, object? value)\n    {\n        foreach (IExifValue exifValue in this.Values)\n        {\n            if (exifValue.Tag == tag)\n            {\n                exifValue.TrySetValue(value);\n                return;\n            }\n        }\n\n        ExifValue? newExifValue = ExifValues.Create(tag) ?? throw new NotSupportedException($\"Newly created value for tag {tag} is null.\");\n\n        newExifValue.TrySetValue(value);\n        this.values.Add(newExifValue);\n    }\n\n    /// <summary>\n    /// Synchronizes the profiles with the specified metadata.\n    /// </summary>\n    /// <param name=\"metadata\">The metadata.</param>\n    internal void Sync(ImageMetadata metadata)\n    {\n        this.SyncResolution(ExifTag.XResolution, metadata.HorizontalResolution);\n        this.SyncResolution(ExifTag.YResolution, metadata.VerticalResolution);\n    }\n\n    internal void SyncDimensions(int width, int height)\n    {\n        if (this.TryGetValue(ExifTag.PixelXDimension, out _))","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/Metadata/Profiles/Exif/ExifProfile.cs#L270-L306","documentation":"ExifProfile.SetValueInternal could not create a new ExifValue for the requested EXIF tag: ExifValues.Create(tag) returned null, meaning the tag has no known type metadata in ImageSharp's EXIF tables, so a NotSupportedException is thrown rather than silently adding an unusable value.","triggerScenarios":"Calling ExifProfile.SetValue(tag, value) with a tag not present in the profile and not in ExifValues' supported tag table — e.g. custom/manufacturer-specific tags or a numeric (ExifTagValue) tag with no registered ExifValue factory.","commonSituations":"Writing maker-note or non-standard EXIF tags that ImageSharp doesn't model; typos in tag constants; trying to write tags added in newer EXIF specs than the library supports.","solutions":["Only set values for tags ImageSharp supports; check support by ensuring ExifValues.Create-equivalent lookup succeeds, or first read the profile to see which tags exist.","For custom tags, add the value to the profile at the raw-data level or via a supported generic tag type instead of SetValue.","Upgrade ImageSharp — newer versions extend the supported EXIF tag table."],"exampleFix":"// before\nprofile.SetValue((ExifTagValue)0x9C9B, \"MyData\"); // unsupported custom tag -> throws\n// after\nif (profile.TryGetValue((ExifTagValue)0x9C9B, out _))\n{\n    profile.SetValue((ExifTagValue)0x9C9B, \"MyData\");\n}\nelse\n{\n    // handle unsupported tag: skip or store elsewhere\n}","handlingStrategy":"try-catch","validationCode":"// Only call SetValue for tags the profile already exposes or that are known-supported\nbool tagWritable(ExifProfile profile, ExifTagValue tag) =>\n    profile.TryGetValue(tag, out _) || Enum.IsDefined(typeof(ExifTagValue), tag); // plus known-supported check","typeGuard":null,"tryCatchPattern":"try { profile.SetValue(tag, value); }\ncatch (NotSupportedException ex)\n{ /* unsupported tag: skip, log, or persist metadata by other means */ }","preventionTips":["Restrict EXIF writes to tags listed by ImageSharp's ExifTag constants.","Check that a profile entry exists (TryGetValue) before setting custom tags.","Keep ImageSharp updated so newly specified EXIF tags become writable."],"tags":["exif","metadata","unsupported-tag","csharp"],"backgroundTag":"unsupported-operation","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"}