Skip to content

Fix Get-AzWebApp deserialization failure for Azure Storage mount type "FileShare" - #29981

Open
Aditya Pujara (a0x1ab) with Copilot wants to merge 4 commits into
mainfrom
copilot/fix-get-azwebapp-deserialization-error
Open

Fix Get-AzWebApp deserialization failure for Azure Storage mount type "FileShare"#29981
Aditya Pujara (a0x1ab) with Copilot wants to merge 4 commits into
mainfrom
copilot/fix-get-azwebapp-deserialization-error

Conversation

Copilot AI commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Get-AzWebApp throws Microsoft.Rest.SerializationException when a web app's azureStorageAccounts configuration contains a mount type value the SDK's AzureStorageType enum doesn't define (e.g. "FileShare", returned for Logic App Standard "File System" connections backed by an SMB share).

Root cause

Microsoft.Azure.Management.WebSites.Models.AzureStorageType only defines AzureFiles/AzureBlob. The enum carries a type-level [JsonConverter(typeof(StringEnumConverter))] attribute, so any unrecognized string value throws instead of degrading gracefully — this attribute-level converter takes precedence over anything registered in JsonSerializerSettings.Converters, so simply adding a converter isn't enough to intercept it.

Fix

  • Added AzureStorageTypeJsonConverter: a lenient JsonConverter for AzureStorageType that returns null for unrecognized values instead of throwing, while still parsing known values normally. WriteJson delegates to StringEnumConverter to preserve correct EnumMember serialization.
  • Added AzureStorageTypeContractResolver: extends ReadOnlyJsonContractResolver (the resolver the generated client uses by default) and overrides ResolveContractConverter to bypass the type-level attribute specifically for AzureStorageType, letting the lenient converter above actually take effect.
  • Wired both into WebsitesClient's DeserializationSettings so all reads through the client tolerate unknown storage mount types.
{
  "azureStorageAccounts": {
    "FileSystem": { "type": "FileShare", "accountName": "..." }
  }
}

now deserializes with Type left null for the unrecognized FileShare value, instead of failing the entire Get-AzWebApp call.

Tests

Added unit tests covering unknown, known, and null type values.

Copilot AI lite review requested due to automatic review settings August 10, 2026 05:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@azure-pipelines

Copy link
Copy Markdown
Contributor
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@azure-pipelines

Copy link
Copy Markdown
Contributor
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@azure-client-tools-agent

Copy link
Copy Markdown

Live test skipped

⏭️ Skipping the live test for this revision because no changed test file was found under a <Service>.Test project (src/<Service>/<Service>.Test/**/*.cs|*.ps1).

The live-test pipeline runs only the scenario/xUnit test files a PR changes, so there is nothing to execute for this commit. This is informational — a regression test is encouraged where it makes sense, but not required. If a test file is added in a later commit, the live test will run automatically.


Posted by agent-assist (autonomous bug-fix pipeline).

@azure-client-tools-agent azure-client-tools-agent Bot added the azure-client-tools-agent Pull request commented on or reviewed by Azure Client Tools Agent label Aug 10, 2026
…are"

Co-authored-by: a0x1ab <59631311+a0x1ab@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 10, 2026 05:47
Co-authored-by: a0x1ab <59631311+a0x1ab@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix Get-AzWebApp to handle Azure Storage mount type 'FileShare' Fix Get-AzWebApp deserialization failure for Azure Storage mount type "FileShare" Aug 10, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Suppressed comments (2)

src/Websites/Websites.Test/ScenarioTests/AzureStorageTypeJsonConverterTests.cs:21

  • The test file's namespace uses WebApps even though the Websites test project root namespace and other ScenarioTests use Microsoft.Azure.Commands.Websites.Test.ScenarioTests. This inconsistency makes navigation/search harder and deviates from the established naming used across the project.
namespace Microsoft.Azure.Commands.WebApps.Test.ScenarioTests

src/Websites/Websites/Utilities/AzureStorageTypeJsonConverter.cs:51

  • Enum.TryParse will successfully parse numeric strings (and may accept values not actually defined in AzureStorageType), which conflicts with the intent of treating unknown values as null. Consider validating the parsed enum value is one of the defined members (and treating whitespace-only values as null) so truly unknown values don't get surfaced as an undefined enum value.
            string value = reader.Value?.ToString();
            AzureStorageType result;
            if (!string.IsNullOrEmpty(value) && Enum.TryParse(value, ignoreCase: true, result: out result))
            {
                return result;

Copilot AI review requested due to automatic review settings August 10, 2026 05:53
@azure-client-tools-agent

Copy link
Copy Markdown

Live test results — TestFx Record (changed test files only)

FAIL (exit )

Test projects: src/Websites/Websites.Test
Filter: FullyQualifiedName~AzureStorageTypeJsonConverterTests
PR head ref: copilot/fix-get-azwebapp-deserialization-error
PR head sha: 7ae1968f711ab0c646d9cf5f095ceea7dd40a378
PR base ref: main

Changed test files run
src/Websites/Websites.Test/ScenarioTests/AzureStorageTypeJsonConverterTests.cs

Workflow run: https://github.com/Azure/issue-sentinel/actions/runs/31360062058

Last 80 lines of dotnet test output
(no log captured)

Posted by agent-assist PowerShell live-test workflow.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Suppressed comments (3)

src/Websites/Websites/Utilities/AzureStorageTypeJsonConverter.cs:52

  • ReadJson uses Enum.TryParse on the enum member name, which may not match the SDK's StringEnumConverter behavior (e.g., EnumMember values, naming strategies). To preserve SDK-compatible parsing while still being lenient for unknown values, delegate to StringEnumConverter.ReadJson and swallow the known exceptions, returning null for unrecognized values.
            string value = reader.Value?.ToString();
            AzureStorageType result;
            if (!string.IsNullOrEmpty(value) && Enum.TryParse(value, ignoreCase: true, result: out result))
            {
                return result;

src/Websites/Websites/Utilities/AzureStorageTypeJsonConverter.cs:80

  • ResolveContractConverter only checks for AzureStorageType, but the contract resolver can be asked about Nullable depending on how the contract is built. Using the same nullable-unwrapping logic as CanConvert makes this more robust and avoids reintroducing the original failure if the resolver receives a nullable type.
        protected override JsonConverter ResolveContractConverter(Type objectType)
        {
            if (objectType == typeof(AzureStorageType))
            {
                return null;

src/Websites/Websites.Test/ScenarioTests/AzureStorageTypeJsonConverterTests.cs:21

  • This test file's namespace uses "WebApps" but the rest of Websites.Test scenario tests use the "Websites" namespace prefix. Aligning the namespace keeps test organization consistent and makes it easier to locate alongside other Websites scenario tests.
namespace Microsoft.Azure.Commands.WebApps.Test.ScenarioTests

@azure-client-tools-agent azure-client-tools-agent Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated CI + Live-Test Review — PR #29981

CI checks: ✅ all passed (2/2).

Live test (TestFx Record):FAILED

The dotnet test run for AzureStorageTypeJsonConverterTests exited non-zero
(no captured stdout/log was available from the runner, but the job step
explicitly reported TestFx tests failed). This test exercises the
AzureStorageTypeJsonConverter used to deserialize Get-AzWebApp mount
configuration, which is exactly what this PR (fix for issue #29979,
Get-AzWebApp deserialization failure for Azure Storage mount type
FileShare) is meant to fix. Please:

  1. Re-run src/Websites/Websites.Test/ScenarioTests/AzureStorageTypeJsonConverterTests.cs
    locally and inspect the actual assertion failure/exception.
  2. Verify the FileShare mount type fix in the converter/deserialization code
    handles all enum cases and any recorded HTTP session fixtures the test
    relies on (check for a matching .json session record under
    src/Websites/Websites.Test/SessionRecords/ if the test uses TestFx
    playback).
  3. Push a fix so this test passes, then this PR will be re-reviewed
    automatically.

Posted by agent-assist (autonomous bug-fix pipeline).

@azure-client-tools-agent

Copy link
Copy Markdown

Started a Copilot task using claude-sonnet-4.6 for the automated review at #29981 (review): https://github.com/Azure/azure-powershell/tasks/2ff3a4b8-2499-4998-b493-af8bcf593970


Posted by agent-assist (autonomous bug-fix pipeline).

Co-authored-by: a0x1ab <59631311+a0x1ab@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 10, 2026 06:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Suppressed comments (1)

src/Websites/Websites/Utilities/AzureStorageTypeJsonConverter.cs:80

  • AzureStorageTypeContractResolver only bypasses the enum’s type-level JsonConverter when ResolveContractConverter is called with objectType == typeof(AzureStorageType). In the original failure stack trace, Json.NET was converting to System.Nullable, so ResolveContractConverter may be asked about the nullable wrapper type as well. Handling the nullable case defensively avoids regressions where the SDK’s StringEnumConverter attribute would still take precedence and throw on unknown values.
        protected override JsonConverter ResolveContractConverter(Type objectType)
        {
            if (objectType == typeof(AzureStorageType))
            {
                return null;
            }

            return base.ResolveContractConverter(objectType);
        }

@azure-client-tools-agent

Copy link
Copy Markdown

Live test results — TestFx Record (changed test files only)

PASS

Test projects: src/Websites/Websites.Test
Filter: FullyQualifiedName~AzureStorageTypeJsonConverterTests
PR head ref: copilot/fix-get-azwebapp-deserialization-error
PR head sha: d22e58d45c820959460d30982dfb39d523cf6a7d
PR base ref: main

Changed test files run
src/Websites/Websites.Test/ScenarioTests/AzureStorageTypeJsonConverterTests.cs

Workflow run: https://github.com/Azure/issue-sentinel/actions/runs/31361707285

Last 80 lines of dotnet test output
Test run for /home/runner/work/issue-sentinel/issue-sentinel/azure-powershell/src/Websites/Websites.Test/bin/Debug/net8.0/Microsoft.Azure.PowerShell.Cmdlets.Websites.Test.dll (.NETCoreApp,Version=v8.0)
A total of 1 test files matched the specified pattern.
Results File: /home/runner/work/issue-sentinel/issue-sentinel/test-output/Websites.Test.trx

Passed!  - Failed:     0, Passed:     3, Skipped:     0, Total:     3, Duration: 34 ms - Microsoft.Azure.PowerShell.Cmdlets.Websites.Test.dll (net8.0)

Posted by agent-assist PowerShell live-test workflow.

@azure-client-tools-agent azure-client-tools-agent Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated Review Summary

PR: Fix Get-AzWebApp deserialization failure for Azure Storage mount type "FileShare" (fixes #29979)

Tester (live-test-powershell.yml): ✅ Passed — TestFx Record run completed successfully for the changed test file(s).

CI checks: ✅ 2/2 checks passed, no failures, nothing pending.

Everything is green. No further action needed from the automated pipeline; ready for human/maintainer review and merge decision.


Posted by agent-assist (autonomous bug-fix pipeline).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

azure-client-tools-agent Pull request commented on or reviewed by Azure Client Tools Agent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Get-AzWebApp fails to deserialize Azure Storage mount type "FileShare"

3 participants