{"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/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Cosmos/Extensions/CosmosComplexCollectionTypePropertyBuilderExtensions.cs#L127-L151","documentation":"The ValidateVectorDistanceFunction method in CosmosComplexCollectionTypePropertyBuilderExtensions checks that the provided DistanceFunction enum value is defined using Enum.IsDefined. If the value falls outside the defined enum range (e.g., a cast from an invalid integer), the method throws ArgumentException. This guards the IsVectorProperty configuration against undefined distance metrics for Cosmos vector search.","triggerScenarios":"Calling IsVectorProperty((DistanceFunction)999, dimensions) or IsVectorProperty((DistanceFunction)(-1), dimensions) — passing an enum value that is not one of the defined members (Cosine, DotProduct, Euclidean). Can also occur if the enum value is cast from an external integer source without validation.","commonSituations":"Deserializing a DistanceFunction from user input or configuration that may contain invalid integer values; casting an integer to DistanceFunction without bounds checking; version mismatch where a newer SDK added enum values not present in the referenced version.","solutions":["Use a named DistanceFunction enum member: DistanceFunction.Cosine, DistanceFunction.DotProduct, or DistanceFunction.Euclidean.","If the value comes from external input, validate with Enum.IsDefined<DistanceFunction>(value) before passing it to IsVectorProperty.","Update the Microsoft.Azure.Cosmos package to ensure the enum definition matches expected values."],"exampleFix":"// before — casting unchecked integer\nvar df = (DistanceFunction)configValue; // configValue could be 999\nbuilder.IsVectorProperty(df, 1536);\n\n// after — validate before use\nvar df = Enum.IsDefined<DistanceFunction>(configValue)\n    ? (DistanceFunction)configValue\n    : DistanceFunction.Cosine;\nbuilder.IsVectorProperty(df, 1536);","handlingStrategy":"validation","validationCode":"// Validate the enum before calling IsVectorProperty\nDistanceFunction df = GetDistanceFunctionFromConfig();\nif (!Enum.IsDefined(df))\n{\n    df = DistanceFunction.Cosine; // or throw\n}\nbuilder.IsVectorProperty(df, dimensions);","typeGuard":"static bool IsValidDistanceFunction(DistanceFunction df) => Enum.IsDefined(df);","tryCatchPattern":null,"preventionTips":["Use named enum members (DistanceFunction.Cosine, DotProduct, Euclidean) rather than integer casts.","Validate externally-sourced integer values with Enum.IsDefined<DistanceFunction> before casting.","Keep the Microsoft.Azure.Cosmos SDK version in sync with EF Core Cosmos package to avoid enum mismatches."],"tags":["ef-core","cosmos","vector-search","enum-validation","configuration"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}