{"record":{"id":"70a7f6f1a4ef9362","repo":"dotnet/efcore","slug":"the-value-value-provided-for-argument-argume","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/CosmosComplexCollectionTypePropertyBuilderExtensions.cs","lineNumber":145,"sourceCode":"    ///     See <see href=\"https://aka.ms/efcore-docs-complex-types\">Complex types</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    /// <typeparam name=\"TProperty\">The type of the property being configured.</typeparam>\n    /// <param name=\"propertyBuilder\">The builder for the property being configured.</param>\n    /// <param name=\"distanceFunction\">The distance function for a vector comparisons.</param>\n    /// <param name=\"dimensions\">The number of dimensions in the vector.</param>\n    /// <returns>The same builder instance so that multiple calls can be chained.</returns>\n    public static ComplexCollectionTypePropertyBuilder<TProperty> IsVectorProperty<TProperty>(\n        this ComplexCollectionTypePropertyBuilder<TProperty> propertyBuilder,\n        DistanceFunction distanceFunction,\n        int dimensions)\n        => (ComplexCollectionTypePropertyBuilder<TProperty>)((ComplexCollectionTypePropertyBuilder)propertyBuilder).IsVectorProperty(\n            distanceFunction, dimensions);\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","sourceCodeStart":127,"sourceCodeEnd":151,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Cosmos/Extensions/CosmosComplexCollectionTypePropertyBuilderExtensions.cs#L127-L151","documentation":"Thrown by ValidateVectorDistanceFunction when the DistanceFunction argument is not a defined enum value. The Cosmos vector indexing feature needs a concrete distance function, so an undefined/(int-cast) enum member is rejected at configuration time. Fires inside IsVectorProperty when building the Cosmos model.","triggerScenarios":"Calling propertyBuilder.IsVectorProperty((DistanceFunction)999, dimensions) or otherwise passing a DistanceFunction value not declared in the enum. Common when casting an arbitrary int to the enum or reading the value from unvalidated config.","commonSituations":"Casting an int from config/JSON into DistanceFunction without range-checking. Refactoring/renaming enum members and forgetting to update stored values. Defaulting an uninitialized enum field (value 0) when 0 is not a valid member.","solutions":["Pass a declared DistanceFunction member (e.g., DistanceFunction.Cosine, DotProduct, or Euclidean per the enum definition).","Validate external values with Enum.IsDefined(typeof(DistanceFunction), value) before passing them in.","If reading from config, map unknown values to a sensible default rather than casting blindly."],"exampleFix":"// before\nvar df = (DistanceFunction)99;\npropertyBuilder.IsVectorProperty(df, 1536); // throws\n\n// after\nvar df = Enum.IsDefined(typeof(DistanceFunction), raw) ? (DistanceFunction)raw : DistanceFunction.Cosine;\npropertyBuilder.IsVectorProperty(df, 1536);","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(DistanceFunction), value))\n{\n    throw new ArgumentException($\"{value} is not a valid DistanceFunction.\", nameof(value));\n}\npropertyBuilder.IsVectorProperty(value, dimensions);","typeGuard":"static bool IsValidDistanceFunction(DistanceFunction value)\n    => Enum.IsDefined(typeof(DistanceFunction), value);","tryCatchPattern":null,"preventionTips":["Validate enum values from config with Enum.IsDefined before casting/passing them.","Map unknown enum ints to a known default at the config boundary.","Add a test covering all declared DistanceFunction members plus an invalid sentinel."],"tags":["ef-core","cosmos","vector","enum","configuration","argument-validation"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}