skip to Main Content

I’m encountering a System.FormatException when trying to build my all Azure Bicep file into an ARM template JSON.

The command I am using is:

simple.bicep

resource storageAccount 'Microsoft.Storage/storageAccounts@2021-04-01' = {
  name: 'mystorageaccount'
  location: 'West US'
  kind: 'StorageV2'
  sku: {
    name: 'Standard_LRS'
  }
}
bicep build simple.bicep --outfile simple.json
Unhandled exception. System.FormatException: The input string 'dons/microsoft.addons/2017-05-15/types.json#/17' was not in a correct format.
   at System.Number.ThrowFormatException[TChar](ReadOnlySpan`1)
   at System.Number.ThrowOverflowOrFormatException[TChar,TInteger](ParsingStatus, ReadOnlySpan`1)
   at System.Number.ParseBinaryInteger[TChar,TInteger](ReadOnlySpan`1, NumberStyles, NumberFormatInfo)
   at System.Int32.Parse(ReadOnlySpan`1 s, NumberStyles style, IFormatProvider provider)
   at System.Int32.Parse(String s, NumberStyles style, IFormatProvider provider)
   at System.Int32.Parse(String s)
   at Azure.Bicep.Types.Serialization.CrossFileTypeReferenceConverter.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
   at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader&, Type, JsonSerializerOptions, ReadStack& , T& , Boolean& )
   at System.Text.Json.Serialization.JsonDictionaryConverter`3.OnTryRead(Utf8JsonReader&, Type, JsonSerializerOptions, ReadStack& , TDictionary& )
   at System.Text.Json.Serialization.Converters.JsonMetadataServicesConverter`1.OnTryRead(Utf8JsonReader&, Type, JsonSerializerOptions, ReadStack& , T& )
   at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader&, Type, JsonSerializerOptions, ReadStack& , T& , Boolean& )
   at System.Text.Json.Serialization.JsonConverter`1.TryReadAsObject(Utf8JsonReader&, Type, JsonSerializerOptions, ReadStack& , Object& )
   at System.Text.Json.Serialization.Converters.LargeObjectWithParameterizedConstructorConverter`1.ReadAndCacheConstructorArgument(ReadStack& , Utf8JsonReader&, JsonParameterInfo)
   at System.Text.Json.Serialization.Converters.ObjectWithParameterizedConstructorConverter`1.ReadConstructorArgumentsWithContinuation(ReadStack& , Utf8JsonReader&, JsonSerializerOptions)
   at System.Text.Json.Serialization.Converters.ObjectWithParameterizedConstructorConverter`1.OnTryRead(Utf8JsonReader&, Type, JsonSerializerOptions, ReadStack& , T& )
   at System.Text.Json.Serialization.Converters.JsonMetadataServicesConverter`1.OnTryRead(Utf8JsonReader&, Type, JsonSerializerOptions, ReadStack& , T& )
   at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader&, Type, JsonSerializerOptions, ReadStack& , T& , Boolean& )
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader&, JsonSerializerOptions, ReadStack&)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.ContinueDeserialize(ReadBufferState&, JsonReaderState&, ReadStack&)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.Deserialize(Stream)
   at System.Text.Json.JsonSerializer.Deserialize[TValue](Stream , JsonSerializerOptions )
   at Azure.Bicep.Types.Serialization.TypeSerializer.DeserializeIndex(Stream contentStream)
   at Azure.Bicep.Types.TypeLoader.LoadTypeIndex()
   at Bicep.Core.TypeSystem.Providers.Az.AzResourceTypeLoader..ctor(ITypeLoader typeLoader)
   at Bicep.Core.Semantics.Namespaces.AzNamespaceType.<>c.<.cctor>b__27_0()
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper, Boolean)
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.get_Value()
   at Bicep.Core.Semantics.Namespaces.AzNamespaceType.get_BuiltInTypeProvider()
   at Bicep.Core.TypeSystem.Providers.ResourceTypeProviderFactory.GetBuiltInAzResourceTypesProvider()
   at Bicep.Core.Semantics.Namespaces.NamespaceProvider.GetNamespaceTypeForConfigManagedProvider(RootConfiguration rootConfig, IFeatureProvider features, BicepSourceFile sourceFile, ResourceScope targetScope, ArtifactResolutionInfo artifact, ProviderDeclarationSyntax syntax, String providerName)
   at Bicep.Core.Semantics.Namespaces.NamespaceProvider.GetNamespaceTypeForImplicitProvider(RootConfiguration rootConfig, IFeatureProvider features, BicepSourceFile sourceFile, ResourceScope targetScope, ImplicitProvider implicitProvider, ProviderDeclarationSyntax syntax)
   at Bicep.Core.Semantics.Namespaces.NamespaceProvider.GetNamespaces(RootConfiguration rootConfig, IFeatureProvider features, IArtifactFileLookup artifactFileLookup, BicepSourceFile sourceFile, ResourceScope targetScope)+MoveNext()
   at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1)
   at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1)
   at System.Collections.Immutable.ImmutableArray.CreateRange[T](IEnumerable`1 items)
   at System.Collections.Immutable.ImmutableArray.ToImmutableArray[TSource](IEnumerable`1)
   at Bicep.Core.Semantics.Binder..ctor(INamespaceProvider namespaceProvider, RootConfiguration configuration, IFeatureProvider features, IArtifactFileLookup sourceFileLookup, ISemanticModelLookup modelLookup, BicepSourceFile sourceFile, ISymbolContext symbolContext)
   at Bicep.Core.Semantics.SemanticModel..ctor(Compilation compilation, BicepSourceFile sourceFile)
   at Bicep.Core.Semantics.Compilation.CreateSemanticModel(BicepSourceFile bicepFile)
   at Bicep.Core.Semantics.Compilation.<>c__DisplayClass1_1.<.ctor>b__2()
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper, Boolean)
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.get_Value()
   at Bicep.Core.Semantics.Compilation.GetSemanticModel(ISourceFile sourceFile)
   at Bicep.Core.Semantics.Compilation.GetSemanticModel[T](ISourceFile sourceFile)
   at Bicep.Core.Semantics.Compilation.GetSemanticModel(BicepSourceFile bicepFile)
   at Bicep.Core.Semantics.Compilation.<GetAllDiagnosticsByBicepFile>b__31_1(BicepSourceFile bicepFile)
   at System.Collections.Immutable.ImmutableDictionary.<>c__DisplayClass9_0`3.<ToImmutableDictionary>b__0(TSource element)
   at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
   at System.Collections.Immutable.ImmutableDictionary`2.AddRange(IEnumerable`1, MutationInput, KeyCollisionBehavior )
   at System.Collections.Immutable.ImmutableDictionary`2.AddRange(IEnumerable`1, Boolean)
   at System.Collections.Immutable.ImmutableDictionary`2.AddRange(IEnumerable`1 )
   at System.Collections.Immutable.ImmutableDictionary.ToImmutableDictionary[TSource,TKey,TValue](IEnumerable`1, Func`2, Func`2, IEqualityComparer`1 , IEqualityComparer`1 )
   at System.Collections.Immutable.ImmutableDictionary.ToImmutableDictionary[TSource,TKey,TValue](IEnumerable`1, Func`2, Func`2)
   at Bicep.Core.Semantics.Compilation.GetAllDiagnosticsByBicepFile()
   at Bicep.Cli.Logging.DiagnosticLogger.LogDiagnostics(DiagnosticOptions options, Compilation compilation)
   at Bicep.Cli.Commands.BuildCommand.RunAsync(BuildArguments args)
   at Bicep.Cli.Program.RunAsync(String[] args, CancellationToken cancellationToken)
   at Bicep.Cli.Program.<>c__DisplayClass3_0.<<Main>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Bicep.Cli.Program.RunWithCancellationAsync(Func`2 runFunc)
   at Bicep.Cli.Program.Main(String[] args)
   at Bicep.Cli.Program.<Main>(String[] args)
  • Bicep CLI version: 0.28.1
  • Azure CLI version: 2.62.0
  • Operating System: Windows 11 Pro

What could be causing this System.FormatException, and how can I resolve it to successfully build my Bicep file into a JSON ARM template?

Thank you for your help!

2

Answers


  1. Chosen as BEST ANSWER

    The issue was related to the culture settings of my system. Specifically, the Thai culture (th-TH) was causing the IndexOf method to return incorrect values, leading to the System.FormatException.

    Steps to Resolve:

    1. Check Current Culture Settings powershell Get-Culture

    2. Change the Culture to en-US for the Current PowerShell Session powershell

    [System.Threading.Thread]::CurrentThread.CurrentCulture = $culture
    [System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture
    

    Credit https://github.com/Azure/bicep/pull/14572


  2. You are missing some commas, try:

    name: 'mystorageaccount',
      location: 'West US',
      kind: 'StorageV2',
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search