Azure ArmResourceType Generator Bug Revisited
When the Azure SDK generator uses @@alternateType to map armResourceType, it mistakenly emits WriteObjectValue(ResourceType, options) instead of the correct WriteStringValue. This happens because WriteObjectValue<T> can’t handle the readonly struct ResourceType, triggering a NotSupportedException.
This glitch disrupts 230 of 287 storage account tests, especially during setup flows like CheckStorageAccountNameAvailability.
Here’s the core: the bug stems from a misalignment in how alternate types are handled - native property use works fine, but @@alternateType falls back to a flawed serialization path.
The workaround demands a custom CodeGenSerialization hook that forces WriteStringValue for ResourceType, but only after regenerating the code.
Crucially, this isn’t a runtime error - it’s a missing public method in the generated deserializer. Developers must regenerate after updating the @@alternateType mapping to fix it.
Isn’t it ironic that a shortcut meant to simplify serialization now introduces a hidden dependency on regeneration?
The bottom line: always verify the generated code after altering @@alternateType mappings. And next time you see a NotSupportedException, it might not be a bug in the code - but in how Azure’s tools interpret it.