{"record":{"id":"1b8e15c0f4593569","repo":"dotnet/efcore","slug":"the-value-value-provided-for-argument-argume-1b8e15","errorCode":null,"errorMessage":"The value '{value}' provided for argument '{argumentName}' must be a valid value of enum type '{enumType}'.","messagePattern":"The value '(.+?)' provided for argument '(.+?)' must be a valid value of enum type '(.+?)'\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Cosmos/Extensions/CosmosPropertyBuilderExtensions.cs","lineNumber":212,"sourceCode":"    /// <returns><see langword=\"true\" /> if the vector distance function and dimensions can be set.</returns>\n    public static bool CanSetIsVectorProperty(\n        this IConventionPropertyBuilder propertyBuilder,\n        DistanceFunction distanceFunction,\n        int dimensions,\n        bool fromDataAnnotation = false)\n        => propertyBuilder.CanSetAnnotation(\n                CosmosAnnotationNames.VectorDistanceFunction,\n                ValidateVectorDistanceFunction(distanceFunction),\n                fromDataAnnotation)\n            && propertyBuilder.CanSetAnnotation(\n                CosmosAnnotationNames.VectorDimensions,\n                dimensions,\n                fromDataAnnotation);\n\n    private static DistanceFunction ValidateVectorDistanceFunction(DistanceFunction distanceFunction)\n        => Enum.IsDefined(distanceFunction)\n            ? distanceFunction\n            : throw new ArgumentException(\n                CoreStrings.InvalidEnumValue(\n                    distanceFunction,\n                    nameof(distanceFunction),\n                    typeof(DistanceFunction)));\n\n    /// <summary>\n    ///     Configures this property to be the etag concurrency token.\n    /// </summary>\n    /// <remarks>\n    ///     See <see href=\"https://aka.ms/efcore-docs-modeling\">Modeling entity types and relationships</see>, and\n    ///     <see href=\"https://aka.ms/efcore-docs-cosmos\">Accessing Azure Cosmos DB with EF Core</see> for more information and examples.\n    /// </remarks>\n    /// <param name=\"propertyBuilder\">The builder for the property being configured.</param>\n    /// <returns>The same builder instance so that multiple calls can be chained.</returns>\n    public static PropertyBuilder IsETagConcurrency(this PropertyBuilder propertyBuilder)\n    {\n        propertyBuilder\n            .IsConcurrencyToken()","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Cosmos/Extensions/CosmosPropertyBuilderExtensions.cs#L194-L230","documentation":"IsVectorProperty validates the DistanceFunction argument with Enum.IsDefined. A DistanceFunction value that is not a defined enum member (e.g. (DistanceFunction)999 produced by an invalid cast or bad deserialization) fails the check and throws ArgumentException via CoreStrings.InvalidEnumValue. Defined members include Cosine, Euclidean, and DotProduct.","triggerScenarios":"Casting an arbitrary integer to DistanceFunction that is not a named member; deserializing a DistanceFunction from JSON/config whose value does not map to a defined name; passing default(DistanceFunction) cast through an untyped boundary.","commonSituations":"Reading distance function from a settings file with no schema validation; receiving the value over an API as an int; copy-paste of a numeric code that is out of range.","solutions":["Use a named DistanceFunction member (DistanceFunction.Cosine, .Euclidean, or .DotProduct).","If the value originates from config/API input, validate it first with Enum.TryParse(typeof(DistanceFunction), value, out _) or Enum.IsDefined before passing.","Tighten the config schema to an enum/string so invalid values fail at load time."],"exampleFix":"// before (invalid cast)\nvar df = (DistanceFunction)config.GetValue<int>(\"VectorDistance\");\nb.Property(x => x.Embedding).IsVectorProperty(df, 10);\n\n// after (validate from config)\nvar raw = config[\"VectorDistance\"];\nif (!Enum.TryParse<DistanceFunction>(raw, out var df) || !Enum.IsDefined(df))\n    throw new ConfigurationException($\"Invalid VectorDistance '{raw}'\");\nb.Property(x => x.Embedding).IsVectorProperty(df, 10);","handlingStrategy":"validation","validationCode":"// Validate the enum before configuring the property.\nDistanceFunction df = /* from config */;\nif (!Enum.IsDefined(df))\n    throw new ArgumentException($\"Invalid {nameof(DistanceFunction)} value: {df}\");\nb.Property(x => x.Embedding).IsVectorProperty(df, 10);","typeGuard":"static bool IsValid(DistanceFunction df) => Enum.IsDefined(df);","tryCatchPattern":"try { b.Property(x => x.Embedding).IsVectorProperty(df, dims); }\ncatch (ArgumentException ex) when (ex.Message.Contains(nameof(DistanceFunction)))\n{ throw new ConfigurationException($\"Configure a valid DistanceFunction (Cosine/Euclidean/DotProduct).\", ex); }","preventionTips":["Use named DistanceFunction members, never integer casts.","Validate external/config values with Enum.TryParse + Enum.IsDefined before passing.","Bind config to the enum type directly so invalid values fail at load."],"tags":["cosmos","validation","enum","vector-search","argument"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}