[v0.10 regression] ArtifactsLocationSasToken MissingMethodException Issue
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:
-
Create a blank bicep file and add the following paramters:
param _artifactsLocation stringparam _artifactsLocationSasToken string -
Run the build command through PowerShell:
az bicep build --file .\azuredeploy.bicep -
Command will fail with Unhandled exception. System.MissingMethodException: Attempted to access a missing method.
Additional context


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.
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.
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]
I confirm that removing
-p:PublishTrimmed=trueresolves the issue, but yields a much larger executable.Removing
-p:SuppressTrimAnalysisWarnings=truemakes 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 You could also turn off the linter rule in a bicepconfig.json file.
@StephenWeatherford I can confirm this works when I disable the linter rule.
