{"record":{"id":"961a42574ce660b8","repo":"microsoft/aspire","slug":"expected-a-string-integer-or-nameof-bicepvalueproxy","errorCode":null,"errorMessage":"Expected a string, integer, or {nameof(BicepValueProxy)}.","messagePattern":"Expected a string, integer, or (.+?)\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.Provisioning/BicepValueFactory.cs","lineNumber":507,"sourceCode":"        return new();\n    }\n#pragma warning restore CA1822\n\n    private static BicepValueProxy FromExpression(BicepExpression expression, bool isSecure)\n    {\n        return BicepValueProxy.CreateExpression(expression, isSecure);\n    }\n\n    private static BicepExpression ToExpression(object value)\n    {\n        ArgumentNullException.ThrowIfNull(value);\n\n        return value switch\n        {\n            string literal => literal,\n            int literal => literal,\n            BicepValueProxy proxy => proxy.ToBicepExpression(),\n            _ => throw new ArgumentException($\"Expected a string, integer, or {nameof(BicepValueProxy)}.\", nameof(value))\n        };\n    }\n\n    private static bool IsSecure(object value)\n    {\n        return value is BicepValueProxy proxy && proxy.IsSecure;\n    }\n}\n","sourceCodeStart":489,"sourceCodeEnd":516,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.Provisioning/BicepValueFactory.cs#L489-L516","documentation":"BicepValueFactory.ToExpression converts an indexer's value into a Bicep expression. It supports only string literals, int literals, and BicepValueProxy instances; anything else throws ArgumentException naming the offending parameter. This enforces that only Bicep-expressible primitives flow into generated expressions.","triggerScenarios":"Using the BicepValueProxy Index API with a value of an unsupported type — e.g. long, double, bool, Guid, DateTime, or an enum — as an index/key/argument instead of a string, int, or proxy.","commonSituations":"Passing a bool or enum from host code into an indexer; using a long from a config value; passing a Guid as a resource key; conversion from JSON config delivering nested objects.","solutions":["Convert the value to string or int before indexing (e.g. myLong.ToString(), ((int)myEnum).ToString()).","Wrap complex values via BicepValueProxy/expression helpers instead of raw objects.","If it's an int-like value, ensure it's genuinely int not long (explicit cast).","Check the call site against the accepted set: string, int, BicepValueProxy."],"exampleFix":"// before\nvar value = factory.Index(config.GetSection(\"replicas\").Get<long>()); // long\n\n// after\nvar value = factory.Index(((int)config.GetValue<long>(\"replicas\")).ToString());","handlingStrategy":"type-guard","validationCode":"bool supported = value is string or int or BicepValueProxy;","typeGuard":"bool IsBicepIndexable(object? v) => v is string or int or BicepValueProxy;","tryCatchPattern":"try { expr = factory.Index(raw); }\ncatch (ArgumentException ex) when (ex.ParamName == \"value\") { /* convert raw to string/int and retry */ }","preventionTips":["Convert longs, bools, enums, and Guids to string or int before using them as Bicep index values.","At config boundaries, parse values into the supported primitive types.","Keep a small helper that normalizes config values to string/int before Bicep APIs."],"tags":["azure","bicep","provisioning","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}