bicep icon indicating copy to clipboard operation
bicep copied to clipboard

[v0.10 regression] ArtifactsLocationSasToken MissingMethodException Issue

Open bradmatt275 opened this issue 4 years ago • 6 comments

Bicep version 0.10.13 (026b4da459)

Describe the bug Unhandled exception. System.MissingMethodException occurs when building a bicep file that contains _artifactsLocation and _artifactsLocationSasToken parameter.

This was working on the previous version until I ran az bicep upgrade.

To Reproduce Steps to reproduce the behavior:

  1. Create a blank bicep file and add the following paramters: param _artifactsLocation string param _artifactsLocationSasToken string

  2. Run the build command through PowerShell: az bicep build --file .\azuredeploy.bicep

  3. Command will fail with Unhandled exception. System.MissingMethodException: Attempted to access a missing method.

Additional context image

image

bradmatt275 avatar Sep 08 '22 23:09 bradmatt275

Rebuilding and running v0.10.13 locally does not reproduce the issue, but it is indeed present in the version installed through the Azure CLI.

Installing v0.9.1 through the Azure CLI yields this warning instead, and seems to produce valid JSON output anyway:

Warning linter-internal-error: Analyzer 'core/artifacts-parameters' encountered an unexpected exception. Method not found: 'System.Text.RegularExpressions.MatchCollection System.Text.RegularExpressions.Regex.Matches(System.String, System.String, System.Text.RegularExpressions.RegexOptions)'.

It would seem that v0.10 turns this into a hard error. I don't understand the root cause, though. Since I can't reproduce it when building the Bicep CLI, it seems the issue is somewhere in the process that publishes the tool into the Azure CLI.

MarkpageBxl avatar Sep 09 '22 21:09 MarkpageBxl

I've managed to reproduce the issue. It's related to the flags used to build the release executable in .github/workflows/build.yml:

dotnet publish --configuration ${{ matrix.configuration }} --self-contained true -p:PublishTrimmed=true -p:PublishSingleFile=true -p:TrimmerDefaultAction=copyused -p:SuppressTrimAnalysisWarnings=true -r ${{ matrix.rid }} ./src/Bicep.Cli/Bicep.Cli.csproj

I suspect the trimming logic throws out references to System.Text.RegularExpressions and breaks the application.

MarkpageBxl avatar Sep 09 '22 21:09 MarkpageBxl

I confirm that removing -p:PublishTrimmed=true resolves the issue, but yields a much larger executable.

Removing -p:SuppressTrimAnalysisWarnings=true makes warnings appear, and this one is probably the culprit:

Bicep.Core/Analyzers/Linter/LinterRulesProvider.cs(42,20): error IL2026: Using member 'System.Reflection.Assembly.GetTypes()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Types might be removed. [Bicep.Core/Bicep.Core.csproj]

MarkpageBxl avatar Sep 09 '22 21:09 MarkpageBxl

I confirm that removing -p:PublishTrimmed=true resolves the issue, but yields a much larger executable.

Removing -p:SuppressTrimAnalysisWarnings=true makes warnings appear, and this one is probably the culprit:

Bicep.Core/Analyzers/Linter/LinterRulesProvider.cs(42,20): error IL2026: Using member 'System.Reflection.Assembly.GetTypes()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Types might be removed. [Bicep.Core/Bicep.Core.csproj]

Thank you. Let me know if I can provide more information to assist.

This is the first time I have raised a bug in Github. I wasn't sure if I included everything that was needed.

My workaround at the moment is just rename those parameters:

overrideParameters: '-_artifactsLocationPram $(AzureFileCopy.StorageContainerUri)drop -_artifactsLocationSasTokenPram $(AzureFileCopy.StorageContainerSasToken)'

bradmatt275 avatar Sep 09 '22 23:09 bradmatt275

@bradmatt275 You could also turn off the linter rule in a bicepconfig.json file.

StephenWeatherford avatar Sep 10 '22 01:09 StephenWeatherford

@StephenWeatherford I can confirm this works when I disable the linter rule.

image

bradmatt275 avatar Sep 10 '22 05:09 bradmatt275