Azure / Azure/template-analyzer
[BUG] - Error when analyzing template with experimentalFeaturesEnabled in bicepconfig.json
- Dominant language
- C#
- Stars
- 143
- Forks
- 47
- PR merge metrics
- No merged PRs in 30d
Description
### Describe the bug
It seems that analyzing template which has resource inside always is failing when bicepconfig.json has experimentalFeaturesEnabled.
As an example we can take official sample from Azure github:
https://github.com/Azure/azure-docs-bicep-samples/blob/main/samples/create-storage-account/main.bicep
Exception details:
```
Microsoft.Azure.Templates.Analyzer.Core.TemplateAnalyzerException: Error while evaluating rules.
---> System.InvalidCastException: Cannot cast Newtonsoft.Json.Linq.JProperty to Newtonsoft.Json.Linq.JToken.
at Newtonsoft.Json.Linq.Extensions.Convert[T,U](T token)
at Newtonsoft.Json.Linq.Extensions.Convert[T,U](IEnumerable`1 source)+MoveNext()
at Microsoft.Azure.Templates.Analyzer.RuleEngines.PowerShellEngine.PowerShellRuleEngine.AnalyzeTemplate(TemplateContext templateContext)
at Microsoft.Azure.Templates.Analyzer.Core.TemplateAnalyzer.AnalyzeAllIncludedTemplates(String populatedTemplate, String parameters, String templateFilePath, TemplateContext parentContext, String pathPrefix)
--- End of inner exception stack trace ---
at Microsoft.Azure.Templates.Analyzer.Core.TemplateAnalyzer.AnalyzeAllIncludedTemplates(String populatedTemplate, String parameters, String templateFilePath, TemplateContext parentContext, String pathPrefix)
at Microsoft.Azure.Templates.Analyzer.Core.TemplateAnalyzer.AnalyzeTemplate(String template, String templateFilePath, String parameters)
at Microsoft.Azure.Templates.Analyzer.Cli.CommandLineParser.AnalyzeTemplate(TemplateAndParams templateAndParameters)
```
When I was debugging I found out that temporary json files created from bicep during analyzing differs depend on experimentalFeaturesEnabled, which seems to be causing exception.

### Expected behavior
Bicep is analyzed without throwing exception when experimentalFeaturesEnabled in bicepconfig.json
### Reproduction Steps
1. Sample bicepconfig.json:
```
{
"analyzers": {
"core": {
"enabled": true,
"rules": {
"max-outputs": {
"level": "warning"
},
"explicit-values-for-loc-params": {
"level": "off"
}
}
}
},
"experimentalFeaturesEnabled": {
"userDefinedTypes": true
}
}
```
2. Sample bicep file:
https://github.com/Azure/azure-docs-bicep-samples/blob/main/samples/create-storage-account/main.bicep
3. Run:
`TemplateAnalyzer.exe analyze-template C:\main.bicep -v`
### Environment
Template Analyzer Version: 0.5.2
.NET version: 7.0.102
IDE: Visual Studio 2022 (17.4.4)
Contributor guide
Assessment
This issue has not been assessed yet.