Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] - Error when analyzing template with experimentalFeaturesEnabled in bicepconfig.json #343

Open
pczar1 opened this issue Aug 28, 2023 · 3 comments
Labels
bug Something isn't working 🔍 needs-triage

Comments

@pczar1
Copy link

pczar1 commented Aug 28, 2023

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.

image

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
    }
}
  1. Sample bicep file:

https://github.com/Azure/azure-docs-bicep-samples/blob/main/samples/create-storage-account/main.bicep

  1. 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)

@pczar1 pczar1 added bug Something isn't working 🔍 needs-triage labels Aug 28, 2023
@nonik0
Copy link
Contributor

nonik0 commented Oct 12, 2023

Thanks for reporting. Template-Analyzer is currently using an older version of bicep since template-analyzer is still targeting .NET6. We'll be moving to the latest Bicep.Core on .NET7 which may fix this issue with the next release.

@nonik0
Copy link
Contributor

nonik0 commented Mar 8, 2024

Template Analyzer was recently updated to the latest version of Bicep and .NET 8, so it's possible this issue is resolved. Could you try with version 0.7.0?

@derlarsschneider
Copy link

still open even with 0.8.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 🔍 needs-triage
Projects
None yet
Development

No branches or pull requests

3 participants