System.FormatException when building Azure Bicep file to JSON

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!

New contributor

ทศพล พิทยาสาธิต is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

You are missing some commas, try:

name: 'mystorageaccount',
  location: 'West US',
  kind: 'StorageV2',

2

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

New contributor

ทศพล พิทยาสาธิต is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật